import java.awt.event.*;
import java.awt.*;
public class ButtonDemo {
public static void main(String args[])
{
Button b;
ActionListener a1 = new MyActionListener();
Frame f1 = new Frame("Java Applet");
f1.add(b1 = new Button("BonjourDemo"), BorderLayout.SOUTH);
b1.setActionCommand("Welcome");
b1.addActionListener(a1);
f1.add(b1 = new Button("NIce day"), BorderLayout.SOUTH);
b1.addActionListener(a1);
b1.addActionListener(a1);
f1.pack();
f1.show();
}
}
class MyActionListenerDemo implements ActionListener {
public void actionPerformed(ActionEvent ae)
{
String s1 = ae1.getActionCommand();
if (s1.equals("ButtonName")) {
System.exit(0);
}
else if (s1.equals("BonjourDemo")) {
System.out.println("Welcome");
}
}
}
Bookmarks