//: Button2NewB.java * An application and an Applet import java.awt.*; import java.awt.event.*; // Must add this import java.applet.*; public class Button2NewB extends Applet { Button b1, b2; TextField t = new TextField(20); public void init() { b1 = new Button("Button 1"); b2 = new Button("Button 2"); b1.addActionListener(new B1()); b2.addActionListener(new B2()); add(b1); add(b2); 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"); } // To close the application: static class WL extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } // A main() for the application: public static void main(String args[]) { Button2NewB applet = new Button2NewB(); Frame aFrame = new Frame("Button2NewB"); aFrame.addWindowListener(new WL()); aFrame.add("Center", applet); aFrame.setSize(300,200); applet.init(); applet.start(); aFrame.setVisible(true); } ///:~
Java Alley | The New AWT Event Model in Java 1.1 (Web Techniques, Aug 1997)
Related Reading
More Insights
INFO-LINK
To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |