Code /* TestBinCalc.java CIS 260 2006-03-01 David Klick Application used to test BinCalc component. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TestBinCalc extends JFrame implements ActionListener { BinCalc cmp; public static void main(String[] args) { TestBinCalc app = new TestBinCalc(); } public TestBinCalc() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new BorderLayout()); cmp = new BinCalc(); c.add(cmp, BorderLayout.CENTER); cmp.addActionListener(this); setSize(400, 100); setVisible(true); } public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); String cmd = e.getActionCommand(); if (cmd.equals("1")) cmp.append('1'); else if (cmd.equals("0")) cmp.append('0'); if (cmd.equals("Clear")) cmp.clear(); if (cmd.equals("Calc")) { JOptionPane.showMessageDialog(null, "" + Integer.parseInt(cmp.getText(), 2), "Your number in base 10", JOptionPane.INFORMATION_MESSAGE); } } }