/* This program implements the "goodbye" demo as posted by John Meacham on the Haskell GUI mailing list. The program is specified as: I propose a simple program which pops up a window saying 'Hello World' with a button saying 'Bye' which you click and it changes the message to 'Goodbye'. if you click the button again the program exits. */ import java.awt.*; import java.awt.event.*; class ByeDemo extends Frame { public static void main(String args[]) { new ByeDemo(); } ByeDemo() { super("Bye!"); setLayout(new FlowLayout(5, 10, 10)); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { ByeDemo.this.dispose(); }}); final Label l = new Label("Hello, world"); final Button b = new Button("Bye"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { l.setText("Goodbye"); b.removeActionListener(this); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ByeDemo.this.dispose(); }}); } }); add(l, BorderLayout.WEST); add(b, BorderLayout.EAST); pack(); show(); } }