Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import javax.swing. * ; import java.awt.event. * ; import java.util. * ; public class Lab 1 extends JFrame implements ActionListener { static final long serialVersionUID

import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Lab1 extends JFrame implements ActionListener {
static final long serialVersionUID =1L;
private JTextField assemblerInstruction;
private JTextField binaryInstruction;
private JTextField hexInstruction;
private JLabel errorLabel;
public Lab1(){
setTitle("M68000");
setBounds(100,100,400,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
assemblerInstruction = new JTextField();
assemblerInstruction.setBounds(25,24,134,28);
getContentPane().add(assemblerInstruction);
assemblerInstruction.setColumns(10);
JLabel lblAssemblyLanguage = new JLabel("Assembly Language");
lblAssemblyLanguage.setBounds(25,64,160,16);
getContentPane().add(lblAssemblyLanguage);
binaryInstruction = new JTextField();
binaryInstruction.setBounds(25,115,180,28);
getContentPane().add(binaryInstruction);
binaryInstruction.setColumns(10);
hexInstruction = new JTextField();
hexInstruction.setBounds(236,115,134,28);
getContentPane().add(hexInstruction);
hexInstruction.setColumns(10);
JLabel lblBinary = new JLabel("Binary Instruction");
lblBinary.setBounds(25,155,190,16);
getContentPane().add(lblBinary);
JLabel lblHexEquivalent = new JLabel("Hex Instruction");
lblHexEquivalent.setBounds(236,155,131,16);
getContentPane().add(lblHexEquivalent);
errorLabel = new JLabel("");
errorLabel.setBounds(25,235,280,16);
getContentPane().add(errorLabel);
JButton btnEncode = new JButton("Encode");
btnEncode.setBounds(230,25,117,29);
getContentPane().add(btnEncode);
btnEncode.addActionListener(this);
JButton btnDecode = new JButton("Decode Binary");
btnDecode.setBounds(30,183,170,29);
getContentPane().add(btnDecode);
btnDecode.addActionListener(this);
JButton btnDecodeHex = new JButton("Decode Hex");
btnDecodeHex.setBounds(230,183,150,29);
getContentPane().add(btnDecodeHex);
btnDecodeHex.addActionListener(this);
}
public void actionPerformed(ActionEvent evt){
errorLabel.setText("");
if (evt.getActionCommand().equals("Encode")){
encode();
} else if (evt.getActionCommand().equals("Decode Binary")){
decodeBin();
} else if (evt.getActionCommand().equals("Decode Hex")){
decodeHex();
}
}
public static void main(String[] args){
Lab1 window = new Lab1();
window.setVisible(true);
}
String shortToHex(short x){
String ans="";
for (int i=0; i<4; i++){
int hex = x & 15;
char hexChar ="0123456789ABCDEF".charAt(hex);
ans = hexChar + ans;
x =(short)(x >>4);
}
return ans;
}
String shortToBinary(short x){
String ans="";
for(int i=0; i<16; i++){
ans =(x & 1)+ ans;
x =(short)(x >>1);
}
return ans;
}
/
************************************************************************/
/* DO NOT CHANGE ANYTHING ABOVE THIS POINT /
/************************************************************************/
}
I need help with creating the encode, decodeBin, and decodeHex

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago