/************************************************************** / Number Converter Applet / IKE / Started: 6/12/01 /**************************************************************/ import java.awt.*; import java.applet.*; import java.awt.event.*; //import java.lang.Object.*; public class NumConverter extends Applet implements ActionListener { public TextField input1, display1, display2, display3; public Label labelTitle, label1input, label2display1, label3display2, label4display3; public Button b1; public Panel p1, p2; Font f; public void init() { f = new Font("", Font.BOLD, 12); setBackground(Color.yellow); p1 = new Panel(new GridLayout(2, 2, 5, 5)); p2 = new Panel(new GridLayout(3, 2, 5, 5)); setLayout(new GridLayout(2, 1, 5, 5)); input1 = new TextField(40); input1.setBackground(Color.white); display1 = new TextField(40); display1.setEditable(false); display1.setBackground(Color.white); display2 = new TextField(40); display2.setEditable(false); display2.setBackground(Color.white); display3 = new TextField(40); display3.setEditable(false); display3.setBackground(Color.white); labelTitle = new Label(""); setFont(f); label1input = new Label("Enter an Integer: "); label2display1 = new Label("Binary"); label3display2 = new Label("Octal"); label4display3 = new Label("Hexadecimal"); b1 = new Button("Convert It!"); b1.addActionListener(this); b1.setBackground(Color.lightGray); p1.add(label1input); p1.add(labelTitle); p1.add(input1); p1.add(b1); p2.add(label2display1); p2.add(display1); p2.add(label3display2); p2.add(display2); p2.add(label4display3); p2.add(display3); add(p2); add(p1); } public void actionPerformed(ActionEvent e) { int num1; String str; str = input1.getText(); num1 = Integer.parseInt(str); str = e.getActionCommand(); display1.setText(Integer.toBinaryString(num1)); display2.setText(Integer.toOctalString(num1)); display3.setText(Integer.toHexString(num1)); } }