//: c13:Label1.java // From Thinking in Java, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 1999 // Copyright notice in Copyright.txt // Using labels // // import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Label1 extends JApplet { JTextField t1 = new JTextField("t1", 10); JLabel labl1 = new JLabel("TextField t1"), labl2 = new JLabel(" "); JButton b1 = new JButton("Test 1"), b2 = new JButton("Test 2"); ActionListener a1 = new ActionListener() { public void actionPerformed(ActionEvent e) { t1.setText("Button 1"); labl2.setText("Text set into Label"); } }; ActionListener a2 = new ActionListener() { public void actionPerformed(ActionEvent e) { t1.setText("Button 2"); labl1.setText("Hello"); } }; public void init() { b1.addActionListener(a1); b2.addActionListener(a2); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(labl1); cp.add(t1); cp.add(b1); cp.add(labl2); cp.add(b2); } } ///:~