[GUI] ByeDemo

Arjan van IJzendoorn afie@cs.uu.nl
Sat, 1 Feb 2003 13:23:16 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_00E0_01C2C9F5.1426C1D0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi,

Here's a Java version of the Bye demo (John Meacham). I think any Haskell
library should at least look better than this.

Arjan

------=_NextPart_000_00E0_01C2C9F5.1426C1D0
Content-Type: application/octet-stream;
	name="ByeDemo.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="ByeDemo.java"

/*
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();
	}
}

------=_NextPart_000_00E0_01C2C9F5.1426C1D0--