// import java.util.*; import com.bruceeckel.swing.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; import com.bruceeckel.swing.*; public class q6 extends JApplet { JButton[] b = new JButton[10]; JTextField txt; JButton c = new JButton("Clear"); JButton q = new JButton("Submit"); ActionListener AL = new ActionListener() { public void actionPerformed(ActionEvent e){ String name = ((JButton)e.getSource()).getText(); if (name.equals("Clear")) txt.setText(""); else if (name.equals("Submit")) { System.out.println("Submitted Value: "+ txt.getText() + "\n" ); System.exit(1); } else txt.setText( txt.getText() + name); } }; public void init() { JPanel cp = new JPanel(); cp.setLayout(new GridLayout(4,3)); for(int i = 1; i < b.length; i++) { b[i] = new JButton("" + i); b[i].addActionListener(AL); cp.add( b[i] ); } c.addActionListener(AL); cp.add( c ); b[9] = new JButton("" + 0); b[9].addActionListener(AL); cp.add( b[9] ); q.addActionListener(AL); cp.add( q ); txt = new JTextField(10); Container p = getContentPane(); p.setLayout(new FlowLayout()); p.add( cp ); p.add( txt ); } public static void main(String[] args) { Console.run(new q6(), 600, 300); } } ///:~