Button2NewB.java


</COMMENT> No Java 2 support for APPLET!!

//: c13:Button2NewB.java
// An application and an applet.
// <applet code=Button2NewB width=250
// height=75></applet>
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.bruceeckel.swing.*;

public class Button2NewB extends JApplet {
  JButton
    b1 = new JButton("Button 1"),
    b2 = new JButton("Button 2");
  JTextField t = new JTextField(20);
  public void init() {
    b1.addActionListener(new B1());
    b2.addActionListener(new B2());
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(b1);
    cp.add(b2);
    cp.add(t);
  }
  class B1 implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      t.setText("Button 1");
    }
  }
  class B2 implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      t.setText("Button 2");
    }
  }
  // A main() for the application:
  public static void main(String[] args) {
    JApplet applet = new Button2NewB();
    JFrame frame = new JFrame("Button2NewB");
    // To close the application:
//#frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.addWindowListener(new WClose()); // 1.2
    frame.getContentPane().add(applet);
    frame.setSize(300,100);
    applet.init();
    applet.start();
    frame.setVisible(true);
  }
} ///:~