FileDocCategorySizeDatePackage
ButtonDemo2b.javaAPI DocExample699Sun Mar 11 21:28:34 GMT 2001None

ButtonDemo2b.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/** Demonstrate use of two buttons, using a single ActionListener 
 * made of a named inner class
 */
public class ButtonDemo2b extends Applet {
	Button b1, b2;
	ActionListener handler = new ButtonHandler();

	public void init() {
		add(b1 = new Button("A button"));
		b1.addActionListener(handler);

		add(b2 = new Button("Another button"));
		b2.addActionListener(handler);
	}

	class ButtonHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == b1)
				showStatus("Thanks for pushing my first button!");
			else
				showStatus("Thanks for pushing my second button!");
		}
	}
}