FileDocCategorySizeDatePackage
Swing.javaAPI DocExample1321Fri Dec 28 15:35:42 GMT 2001None

Swing

public class Swing extends JComponent
Template standalone Swing GUI application.
author
Ian Darwin, ian@darwinsys.com
version
#Id$

Fields Summary
boolean
unsavedChanges
JButton
quitButton
Constructors Summary
public Swing()
Construct the object including its GUI

		super();
		add(new Label("Hello, and welcome to the world of Java"));
		add(quitButton = new JButton("Exit")); 
	
Methods Summary
public static voidmain(java.lang.String[] av)
"main program" method - construct and show


	        
	     
		// create a Swing object, tell it to show up
		final JFrame f = new JFrame("Swing");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Swing comp = new Swing();
		f.getContentPane().add(comp);
		comp.quitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.setVisible(false);
				f.dispose();
				System.exit(0);
			}
		});
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				f.setVisible(false);
				f.dispose();
				System.exit(0);
			}
		});
		f.pack();
		f.setLocation(200, 200);
		f.setVisible(true);