ButtonAppApplet.java


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

//: c13:ButtonAppApplet.java
// Creating an applet-application.
// <applet code=ButtonAppApplet
//  width=375 height=50> </applet>
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import com.bruceeckel.swing.*;

public class ButtonAppApplet extends JApplet {
  JButton 
    b1 = new JButton("Hello"), 
    b2 = new JButton("Howdy");
  JTextField t = new JTextField(15);
  ActionListener al = new ActionListener() {
    public void actionPerformed(ActionEvent e){
      String name = 
        ((JButton)e.getSource()).getText();
      t.setText(name);
    }
  };
  public void init() {
    b1.addActionListener(al);
    b2.addActionListener(al);
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(b1);
    cp.add(b2);
    cp.add(t);
  }
  public static void main(String[] args) {
    JApplet applet = new ButtonAppApplet();
    JFrame frame = new JFrame("ButtonAppApplet");
//#frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.addWindowListener(new WClose()); // 1.2
    frame.getContentPane().add(applet);
    frame.setSize(400,100);
    applet.init();
    applet.start();
    frame.setVisible(true);
  }  
} ///:~