import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
public class Converter5final extends JFrame implements ActionListener
{
public static final int WIDTH = 400;
public static final int HEIGHT = 600;
public static final int NUMBER_OF_DIGITS = 1;
/*private JTextField[] row1;
private JTextField[] row2;
private JTextField[] row3;
private JTextField[] row4;*/
private JTextField txt1;
private JTextField txt2;
private JTextField txt3;
private JTextField txt4;
private JTextField txt5;
private JTextField txt6;
private JTextField txt7;
private JTextField txt8;
private JTextField txt9;
private JTextField txt10;
private JTextField txt11;
private JTextField txt12;
private JTextField txt13;
private JTextField txt14;
private JTextField txt15;
private JTextField txt16;
private JTextField input;
private JTextField output;
private JTextField t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16;
private JTextField s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16;
private JTextField a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16;
private String result="101000", rem;
private int ans = 0, xme =0, op=0;
public static void main(String[] args)
{
Converter5final aConv = new Converter5final();
aConv.setVisible(true);
}
public Converter5final()
{
setTitle("Converter");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(WIDTH, HEIGHT);
setLayout(new GridLayout(8, 1));
setDefaultLookAndFeelDecorated (true);
try
{
UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println ("Failed loading L&F: ");
System.out.println (ex);
}
// Menu
JMenuBar mb = new JMenuBar();
JMenu mnuFile = new JMenu("File");
JMenuItem mnuItemQuit = new JMenuItem("Quit");
JMenu mnuHelp = new JMenu("Help");
JMenuItem mnuItemAbout = new JMenuItem("About");
setJMenuBar(mb);
mnuFile.add(mnuItemQuit);
mnuHelp.add(mnuItemAbout);
mb.add(mnuFile);
mb.add(mnuHelp);
// Allows the Swing App to be closed
addWindowListener(new ListenCloseWdw());
//Add Menu listener
mnuItemQuit.addActionListener(new ListenMenuQuit());
JPanel jp1 = new JPanel();
jp1.setLayout(new FlowLayout());
jp1.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "AX"));
JPanel jp2 = new JPanel();
jp2.setLayout(new FlowLayout());
jp2.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Action"));
JPanel jp3 = new JPanel();
jp3.setLayout(new FlowLayout());
jp3.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "ENTER THE NUMBER"));
JPanel jp4 = new JPanel();
jp4.setLayout(new FlowLayout());
jp4.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "OUTPUT MESSAGE"));
JPanel jp5 = new JPanel();
jp5.setLayout(new FlowLayout());
JPanel jp6 = new JPanel();
jp6.setLayout(new FlowLayout());
jp6.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "BX"));
JPanel jp7 = new JPanel();
jp7.setLayout(new FlowLayout());
jp7.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "CX"));
JPanel jp8 = new JPanel();
jp8.setLayout(new FlowLayout());
jp8.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "DX"));
JPanel jp9 = new JPanel();
jp9.setLayout(new FlowLayout());
///////////////////////////////////////
jp9.setBackground(Color.ORANGE);
jp1.setBackground(Color.ORANGE);
jp2.setBackground(Color.ORANGE);
jp3.setBackground(Color.ORANGE);
jp4.setBackground(Color.ORANGE);
jp4.setBackground(Color.ORANGE);
jp5.setBackground(Color.ORANGE);
jp6.setBackground(Color.ORANGE);
jp7.setBackground(Color.ORANGE);
jp8.setBackground(Color.ORANGE);
JLabel base = new JLabel("Click Base>>");
JLabel num = new JLabel("Dec or Oct or Hex");
txt1 = new JTextField(" ", NUMBER_OF_DIGITS);
txt1.setBackground(Color.WHITE);
txt1.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt1.setEditable (false);
txt1.setHorizontalAlignment (JTextField.CENTER);
//txt1.setFont (new Font ("Andy Bold", Font.PLAIN, 15));
txt2 = new JTextField(" ", NUMBER_OF_DIGITS);
txt2.setBackground(Color.WHITE);
txt2.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt2.setEditable (false);
txt2.setHorizontalAlignment (JTextField.CENTER);
//txt2.setFont (new Font ("Andy Bold", Font.PLAIN, 15));
txt3 = new JTextField(" ", NUMBER_OF_DIGITS);
txt3.setBackground(Color.WHITE);
txt3.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt4 = new JTextField(" ", NUMBER_OF_DIGITS);
txt4.setBackground(Color.WHITE);
txt4.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt5 = new JTextField(" ", NUMBER_OF_DIGITS);
txt5.setBackground(Color.WHITE);
txt5.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt6 = new JTextField(" ", NUMBER_OF_DIGITS);
txt6.setBackground(Color.WHITE);
txt6.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt7 = new JTextField(" ", NUMBER_OF_DIGITS);
txt7.setBackground(Color.WHITE);
txt7.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt8 = new JTextField(" ", NUMBER_OF_DIGITS);
txt8.setBackground(Color.WHITE);
txt8.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt9 = new JTextField(" ", NUMBER_OF_DIGITS);
txt9.setBackground(Color.WHITE);
txt9.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt10 = new JTextField(" ", NUMBER_OF_DIGITS);
txt10.setBackground(Color.WHITE);
txt10.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt11 = new JTextField(" ", NUMBER_OF_DIGITS);
txt11.setBackground(Color.WHITE);
txt11.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt12 = new JTextField(" ", NUMBER_OF_DIGITS);
txt12.setBackground(Color.WHITE);
txt12.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt13 = new JTextField(" ", NUMBER_OF_DIGITS);
txt13.setBackground(Color.WHITE);
txt13.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt14 = new JTextField(" ", NUMBER_OF_DIGITS);
txt14.setBackground(Color.WHITE);
txt14.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt15 = new JTextField(" ", NUMBER_OF_DIGITS);
txt15.setBackground(Color.WHITE);
txt15.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
txt16 = new JTextField(" ", NUMBER_OF_DIGITS);
input = new JTextField(" ", 20);
txt16.setBackground(Color.WHITE);
txt16.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
input.setBackground(Color.WHITE);
output = new JTextField(" ", 10);
output.setBackground(Color.WHITE);
output.setBorder(BorderFactory.createEmptyBorder(5, 3, 5, 3));
//output.setBorder(BorderFactory.createEmptyBorder(5, 3, 5, 3));
t1 = new JTextField("", NUMBER_OF_DIGITS);
t1.setBackground(Color.WHITE);
t1.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t2 = new JTextField(" ", NUMBER_OF_DIGITS);
t2.setBackground(Color.WHITE);
t2.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t3 = new JTextField(" ", NUMBER_OF_DIGITS);
t3.setBackground(Color.WHITE);
t3.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t4 = new JTextField("", NUMBER_OF_DIGITS);
t4.setBackground(Color.WHITE);
t4.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t5 = new JTextField(" ", NUMBER_OF_DIGITS);
t5.setBackground(Color.WHITE);
t5.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t6 = new JTextField(" ", NUMBER_OF_DIGITS);
t6.setBackground(Color.WHITE);
t6.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t7 = new JTextField("", NUMBER_OF_DIGITS);
t7.setBackground(Color.WHITE);
t7.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t8 = new JTextField(" ", NUMBER_OF_DIGITS);
t8.setBackground(Color.WHITE);
t8.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t9 = new JTextField(" ", NUMBER_OF_DIGITS);
t9.setBackground(Color.WHITE);
t9.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t10 = new JTextField("", NUMBER_OF_DIGITS);
t10.setBackground(Color.WHITE);
t10.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t11 = new JTextField(" ", NUMBER_OF_DIGITS);
t11.setBackground(Color.WHITE);
t11.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t12 = new JTextField(" ", NUMBER_OF_DIGITS);
t12.setBackground(Color.WHITE);
t12.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t13 = new JTextField("", NUMBER_OF_DIGITS);
t13.setBackground(Color.WHITE);
t13.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t14 = new JTextField(" ", NUMBER_OF_DIGITS);
t14.setBackground(Color.WHITE);
t14.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t15 = new JTextField(" ", NUMBER_OF_DIGITS);
t15.setBackground(Color.WHITE);
t15.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
t16 = new JTextField(" ", NUMBER_OF_DIGITS);
t16.setBackground(Color.WHITE);
t16.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s1 = new JTextField("", NUMBER_OF_DIGITS);
s1.setBackground(Color.WHITE);
s1.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s2 = new JTextField(" ", NUMBER_OF_DIGITS);
s2.setBackground(Color.WHITE);
s2.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s3 = new JTextField(" ", NUMBER_OF_DIGITS);
s3.setBackground(Color.WHITE);
s3.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s4 = new JTextField("", NUMBER_OF_DIGITS);
s4.setBackground(Color.WHITE);
s4.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s5 = new JTextField(" ", NUMBER_OF_DIGITS);
s5.setBackground(Color.WHITE);
s5.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s6 = new JTextField(" ", NUMBER_OF_DIGITS);
s6.setBackground(Color.WHITE);
s6.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s7 = new JTextField("", NUMBER_OF_DIGITS);
s7.setBackground(Color.WHITE);
s7.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s8 = new JTextField(" ", NUMBER_OF_DIGITS);
s8.setBackground(Color.WHITE);
s8.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s9 = new JTextField(" ", NUMBER_OF_DIGITS);
s9.setBackground(Color.WHITE);
s9.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s10 = new JTextField("", NUMBER_OF_DIGITS);
s10.setBackground(Color.WHITE);
s10.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s11 = new JTextField(" ", NUMBER_OF_DIGITS);
s11.setBackground(Color.WHITE);
s11.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s12 = new JTextField(" ", NUMBER_OF_DIGITS);
s12.setBackground(Color.WHITE);
s12.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s13 = new JTextField("", NUMBER_OF_DIGITS);
s13.setBackground(Color.WHITE);
s13.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s14 = new JTextField(" ", NUMBER_OF_DIGITS);
s14.setBackground(Color.WHITE);
s14.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s15 = new JTextField(" ", NUMBER_OF_DIGITS);
s15.setBackground(Color.WHITE);
s15.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
s16 = new JTextField(" ", NUMBER_OF_DIGITS);
s16.setBackground(Color.WHITE);
s16.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a1 = new JTextField("", NUMBER_OF_DIGITS);
a1.setBackground(Color.WHITE);
a1.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a2 = new JTextField(" ", NUMBER_OF_DIGITS);
a2.setBackground(Color.WHITE);
a2.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a3 = new JTextField(" ", NUMBER_OF_DIGITS);
a3.setBackground(Color.WHITE);
a3.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a4 = new JTextField("", NUMBER_OF_DIGITS);
a4.setBackground(Color.WHITE);
a4.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a5 = new JTextField(" ", NUMBER_OF_DIGITS);
a5.setBackground(Color.WHITE);
a5.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a6 = new JTextField(" ", NUMBER_OF_DIGITS);
a6.setBackground(Color.WHITE);
a6.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a7 = new JTextField("", NUMBER_OF_DIGITS);
a7.setBackground(Color.WHITE);
a7.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a8 = new JTextField(" ", NUMBER_OF_DIGITS);
a8.setBackground(Color.WHITE);
a8.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a9 = new JTextField(" ", NUMBER_OF_DIGITS);
a9.setBackground(Color.WHITE);
a9.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a10 = new JTextField("", NUMBER_OF_DIGITS);
a10.setBackground(Color.WHITE);
a10.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a11 = new JTextField(" ", NUMBER_OF_DIGITS);
a11.setBackground(Color.WHITE);
a11.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a12 = new JTextField(" ", NUMBER_OF_DIGITS);
a12.setBackground(Color.WHITE);
a12.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a13 = new JTextField("", NUMBER_OF_DIGITS);
a13.setBackground(Color.WHITE);
a13.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a14 = new JTextField(" ", NUMBER_OF_DIGITS);
a14.setBackground(Color.WHITE);
a14.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a15 = new JTextField(" ", NUMBER_OF_DIGITS);
a15.setBackground(Color.WHITE);
a15.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
a16 = new JTextField(" ", NUMBER_OF_DIGITS);
a16.setBackground(Color.WHITE);
a16.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
JButton move = new JButton("MOVE");
JButton sub = new JButton("SUB");
JButton add = new JButton("ADD");
JButton Do = new JButton("DO");
JButton clr = new JButton("Clear");
//////////////////////////////////////////////////////////
JButton oc = new JButton("Octal");
JButton de = new JButton("Deci");
JButton he = new JButton("Hexa");
//////////////////////////////////////
JRadioButton oct = new JRadioButton("Oct" , false);
JRadioButton dec = new JRadioButton("Dec" , true);
JRadioButton hex = new JRadioButton("Hex", false);
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(oct);
bgroup.add(dec);
bgroup.add(hex);
//JLabel num = new JButton("Enter Number:");
move.addActionListener(this);
sub.addActionListener(this);
add.addActionListener(this);
Do.addActionListener(this);
clr.addActionListener(this);
////////////////////////////////////////
oc.addActionListener(this);
de.addActionListener(this);
he.addActionListener(this);
JPanel test = new JPanel();
test.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "CLICK BASE"));
test.add(de);
test.add(oc);
test.add(he);
////////////////////////////
oct.addActionListener(this);
dec.addActionListener(this);
hex.addActionListener(this);
jp9.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "CONVERT FROM?"));
jp9.add(dec);
jp9.add(oct);
jp9.add(hex);
jp1.add(txt1); jp6.add(t1); jp7.add(s1); jp8.add(a1);
jp1.add(txt2); jp6.add(t2); jp7.add(s2); jp8.add(a2);
jp1.add(txt3); jp6.add(t3); jp7.add(s3); jp8.add(a3);
jp1.add(txt4); jp6.add(t4); jp7.add(s4); jp8.add(a4);
jp1.add(txt5); jp6.add(t5); jp7.add(s5); jp8.add(a5);
jp1.add(txt6); jp6.add(t6); jp7.add(s6); jp8.add(a6);
jp1.add(txt7); jp6.add(t7); jp7.add(s7); jp8.add(a7);
jp1.add(txt8); jp6.add(t8); jp7.add(s8); jp8.add(a8);
jp1.add(txt9); jp6.add(t9); jp7.add(s9); jp8.add(a9);
jp1.add(txt10); jp6.add(t10); jp7.add(s10); jp8.add(a10);
jp1.add(txt11); jp6.add(t11); jp7.add(s11); jp8.add(a11);
jp1.add(txt12); jp6.add(t12); jp7.add(s12); jp8.add(a12);
jp1.add(txt13); jp6.add(t13); jp7.add(s13); jp8.add(a13);
jp1.add(txt14); jp6.add(t14); jp7.add(s14); jp8.add(a14);
jp1.add(txt15); jp6.add(t15); jp7.add(s15); jp8.add(a15);
jp1.add(txt16); jp6.add(t16); jp7.add(s16); jp8.add(a16);
// jp2.add(move);
jp2.add(Do);
jp2.add(sub);
jp2.add(add);
jp2.add(clr);
jp3.add(num);
jp3.add(input);
jp4.add(output);
getContentPane().add(jp3);
add(test);
getContentPane().add(jp2);
getContentPane().add(jp1);
getContentPane().add(jp6);
getContentPane().add(jp7);
getContentPane().add(jp8);
//add(ResultsPanel);
getContentPane().add(jp4);
//getContentPane().add(jp5);
}
public class ListenMenuQuit implements ActionListener{
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
public class ListenCloseWdw extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
//result=input.getText();
if(actionCommand.equals("Deci"))
{
op = 1;
String s = input.getText();
rem = s;
ans = Integer.parseInt(s);
xme = ans;
//ans= k;
result = Integer.toBinaryString((ans));
}
else if(actionCommand.equals("Hexa"))
{
op = 2;
String s = input.getText();
rem = s;
ans = Integer.parseInt(s, 16);
xme = ans;
//ans = k;
result = Integer.toBinaryString((ans));
}
else if(actionCommand.equals("Octal"))
{
op = 3;
String s = input.getText();
rem = s;
ans = Integer.parseInt(s, 8);
xme = ans;
//ans = k;
result = Integer.toBinaryString((ans));
}
else if(actionCommand.equals("DO"))
{
output.setText("no error");
display();
}
else if(actionCommand.equals("ADD"))
{
txt1.setText(" "); t1.setText(" "); s1.setText(" "); a1.setText(" ");
txt2.setText(" "); t2.setText(" "); s2.setText(" "); a2.setText(" ");
txt3.setText(" "); t3.setText(" "); s3.setText(" "); a3.setText(" ");
txt4.setText(" "); t4.setText(" "); s4.setText(" "); a4.setText(" ");
txt5.setText(" "); t5.setText(" "); s5.setText(" "); a5.setText(" ");
txt6.setText(" "); t6.setText(" "); s6.setText(" "); a6.setText(" ");
txt7.setText(" "); t7.setText(" "); s7.setText(" "); a7.setText(" ");
txt8.setText(" "); t8.setText(" "); s8.setText(" "); a8.setText(" ");
txt9.setText(" "); t9.setText(" "); s9.setText(" "); a9.setText(" ");
txt10.setText(" "); t10.setText(" "); s10.setText(" "); a10.setText(" ");
txt11.setText(" "); t11.setText(" "); s11.setText(" "); a11.setText(" ");
txt12.setText(" "); t12.setText(" "); s12.setText(" "); a12.setText(" ");
txt13.setText(" "); t13.setText(" "); s13.setText(" "); a13.setText(" ");
txt14.setText(" "); t14.setText(" "); s14.setText(" "); a14.setText(" ");
txt15.setText(" "); t15.setText(" "); s15.setText(" "); a15.setText(" ");
txt16.setText(" "); t16.setText(" "); s16.setText(" "); a16.setText(" ");
operationA();
}
else if(actionCommand.equals("SUB"))
{
txt1.setText(" "); t1.setText(" "); s1.setText(" "); a1.setText(" ");
txt2.setText(" "); t2.setText(" "); s2.setText(" "); a2.setText(" ");
txt3.setText(" "); t3.setText(" "); s3.setText(" "); a3.setText(" ");
txt4.setText(" "); t4.setText(" "); s4.setText(" "); a4.setText(" ");
txt5.setText(" "); t5.setText(" "); s5.setText(" "); a5.setText(" ");
txt6.setText(" "); t6.setText(" "); s6.setText(" "); a6.setText(" ");
txt7.setText(" "); t7.setText(" "); s7.setText(" "); a7.setText(" ");
txt8.setText(" "); t8.setText(" "); s8.setText(" "); a8.setText(" ");
txt9.setText(" "); t9.setText(" "); s9.setText(" "); a9.setText(" ");
txt10.setText(" "); t10.setText(" "); s10.setText(" "); a10.setText(" ");
txt11.setText(" "); t11.setText(" "); s11.setText(" "); a11.setText(" ");
txt12.setText(" "); t12.setText(" "); s12.setText(" "); a12.setText(" ");
txt13.setText(" "); t13.setText(" "); s13.setText(" "); a13.setText(" ");
txt14.setText(" "); t14.setText(" "); s14.setText(" "); a14.setText(" ");
txt15.setText(" "); t15.setText(" "); s15.setText(" "); a15.setText(" ");
txt16.setText(" "); t16.setText(" "); s16.setText(" "); a16.setText(" ");
operationB();
}
else if(actionCommand.equals("Clear"))
{
result = " ";
ans = 0;
output.setText(" ");
input.setText("");
txt1.setText(" "); t1.setText(" "); s1.setText(" "); a1.setText(" ");
txt2.setText(" "); t2.setText(" "); s2.setText(" "); a2.setText(" ");
txt3.setText(" "); t3.setText(" "); s3.setText(" "); a3.setText(" ");
txt4.setText(" "); t4.setText(" "); s4.setText(" "); a4.setText(" ");
txt5.setText(" "); t5.setText(" "); s5.setText(" "); a5.setText(" ");
txt6.setText(" "); t6.setText(" "); s6.setText(" "); a6.setText(" ");
txt7.setText(" "); t7.setText(" "); s7.setText(" "); a7.setText(" ");
txt8.setText(" "); t8.setText(" "); s8.setText(" "); a8.setText(" ");
txt9.setText(" "); t9.setText(" "); s9.setText(" "); a9.setText(" ");
txt10.setText(" "); t10.setText(" "); s10.setText(" "); a10.setText(" ");
txt11.setText(" "); t11.setText(" "); s11.setText(" "); a11.setText(" ");
txt12.setText(" "); t12.setText(" "); s12.setText(" "); a12.setText(" ");
txt13.setText(" "); t13.setText(" "); s13.setText(" "); a13.setText(" ");
txt14.setText(" "); t14.setText(" "); s14.setText(" "); a14.setText(" ");
txt15.setText(" "); t15.setText(" "); s15.setText(" "); a15.setText(" ");
txt16.setText(" "); t16.setText(" "); s16.setText(" "); a16.setText(" ");
}
else
input.setText("Unexperted error.");
}
private static double stringToInt(String stringObject)
{
return Integer.parseInt(stringObject);//stringObject.trim()
}
public void doAgain (int res){
result = Integer.toBinaryString((res));
txt1.setText(" "); t1.setText(" "); s1.setText(" "); a1.setText(" ");
txt2.setText(" "); t2.setText(" "); s2.setText(" "); a2.setText(" ");
txt3.setText(" "); t3.setText(" "); s3.setText(" "); a3.setText(" ");
txt4.setText(" "); t4.setText(" "); s4.setText(" "); a4.setText(" ");
txt5.setText(" "); t5.setText(" "); s5.setText(" "); a5.setText(" ");
txt6.setText(" "); t6.setText(" "); s6.setText(" "); a6.setText(" ");
txt7.setText(" "); t7.setText(" "); s7.setText(" "); a7.setText(" ");
txt8.setText(" "); t8.setText(" "); s8.setText(" "); a8.setText(" ");
txt9.setText(" "); t9.setText(" "); s9.setText(" "); a9.setText(" ");
txt10.setText(" "); t10.setText(" "); s10.setText(" "); a10.setText(" ");
txt11.setText(" "); t11.setText(" "); s11.setText(" "); a11.setText(" ");
txt12.setText(" "); t12.setText(" "); s12.setText(" "); a12.setText(" ");
txt13.setText(" "); t13.setText(" "); s13.setText(" "); a13.setText(" ");
txt14.setText(" "); t14.setText(" "); s14.setText(" "); a14.setText(" ");
txt15.setText(" "); t15.setText(" "); s15.setText(" "); a15.setText(" ");
txt16.setText(" "); t16.setText(" "); s16.setText(" "); a16.setText(" ");
if(result.length() <= 16)
{
int j = result.length();
output.setText("Underflow");
for(int i=0; i<=j; i++)
{
char b = result.charAt(i);
String a = Character.toString(b);
if(i==0){
txt1.setText(a);
t1.setText(a);
s1.setText(a);
a1.setText(a);
}
else if(i==1){
txt2.setText(a);
t2.setText(a);
s2.setText(a);
a2.setText(a);
}
else if(i==2){
txt3.setText(a);
t3.setText(a);
s3.setText(a);
a3.setText(a);
}
else if(i==3){
txt4.setText(a);
t4.setText(a);
s4.setText(a);
a4.setText(a);
}
else if(i==4){
txt5.setText(a);
t5.setText(a);
s5.setText(a);
a5.setText(a);
}
else if(i==5){
txt6.setText(a);
t6.setText(a);
s6.setText(a);
a6.setText(a);
}
else if(i==6){
txt7.setText(a);
t7.setText(a);
s7.setText(a);
a7.setText(a);
}
else if(i==7){
txt8.setText(a);
t8.setText(a);
s8.setText(a);
a8.setText(a);
}
else if(i==8){
txt9.setText(a);
t9.setText(a);
s9.setText(a);
a9.setText(a);
}
else if(i==9){
txt10.setText(a);
t10.setText(a);
s10.setText(a);
a10.setText(a);
}
else if(i==10){
txt11.setText(a);
t11.setText(a);
s11.setText(a);
a11.setText(a);
}
else if(i==11){
txt12.setText(a);
t12.setText(a);
s12.setText(a);
a12.setText(a);
}
else if(i==12){
txt13.setText(a);
t13.setText(a);
s13.setText(a);
a13.setText(a);
}
else if(i==13){
txt14.setText(a);
t14.setText(a);
s14.setText(a);
a14.setText(a);
}
else if(i==14){
txt15.setText(a);
t15.setText(a);
s15.setText(a);
a15.setText(a);
}
else if(i==15){
txt16.setText(a);
t16.setText(a);
s16.setText(a);
a16.setText(a);
}
else {}
}
}
else
output.setText("Overflow");
}
public void operationA()
{
switch(op)
{
case 1:{
String i = input.getText();
int j = Integer.parseInt(i);
ans = ans + j;
xme = ans;
result = Integer.toBinaryString(ans);
break;
}
case 2:{
String i = input.getText();
int j = Integer.parseInt(i, 16);
ans = ans + j;
xme = ans;
result = Integer.toBinaryString(ans);
break;
}
case 3:{
String i = input.getText();
int j = Integer.parseInt(i, 8);
ans = ans + j;
xme = ans;
result = Integer.toBinaryString(ans);
break;
}
default:
}
}
public void operationB()
{
switch(op)
{
case 1:{
String i = input.getText();
int j = Integer.parseInt(i);
ans = ans - j;
xme = ans;
result = Integer.toBinaryString(ans);
break;
}
case 2:{
String i = input.getText();
int j = Integer.parseInt(i, 16);
ans = ans - j;
xme = ans;
result = Integer.toBinaryString(ans);
break;
}
case 3:{
String i = input.getText();
int j = Integer.parseInt(i, 8);
ans = ans - j;
xme = ans;
result = Integer.toBinaryString(ans);
break;
}
default:
}
}
public void display()
{
if(result.length() <= 16)
{
int j = result.length();
for(int i=0; i<=j; i++)
{
char b = result.charAt(i);
String a = Character.toString(b);
if(i==0){
txt1.setText(a);
t1.setText(a);
s1.setText(a);
a1.setText(a);
}
else if(i==1){
txt2.setText(a);
t2.setText(a);
s2.setText(a);
a2.setText(a);
}
else if(i==2){
txt3.setText(a);
t3.setText(a);
s3.setText(a);
a3.setText(a);
}
else if(i==3){
txt4.setText(a);
t4.setText(a);
s4.setText(a);
a4.setText(a);
}
else if(i==4){
txt5.setText(a);
t5.setText(a);
s5.setText(a);
a5.setText(a);
}
else if(i==5){
txt6.setText(a);
t6.setText(a);
s6.setText(a);
a6.setText(a);
}
else if(i==6){
txt7.setText(a);
t7.setText(a);
s7.setText(a);
a7.setText(a);
}
else if(i==7){
txt8.setText(a);
t8.setText(a);
s8.setText(a);
a8.setText(a);
}
else if(i==8){
txt9.setText(a);
t9.setText(a);
s9.setText(a);
a9.setText(a);
}
else if(i==9){
txt10.setText(a);
t10.setText(a);
s10.setText(a);
a10.setText(a);
}
else if(i==10){
txt11.setText(a);
t11.setText(a);
s11.setText(a);
a11.setText(a);
}
else if(i==11){
txt12.setText(a);
t12.setText(a);
s12.setText(a);
a12.setText(a);
}
else if(i==12){
txt13.setText(a);
t13.setText(a);
s13.setText(a);
a13.setText(a);
}
else if(i==13){
txt14.setText(a);
t14.setText(a);
s14.setText(a);
a14.setText(a);
}
else if(i==14){
txt15.setText(a);
t15.setText(a);
s15.setText(a);
a15.setText(a);
}
else if(i==15){
txt16.setText(a);
t16.setText(a);
s16.setText(a);
a16.setText(a);
}
else
output.setText("Underflow");
}
}
}
}

No comments:
Post a Comment