Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!