FileDocCategorySizeDatePackage
Swing.javaAPI DocExample1329Sun Feb 08 21:34:06 GMT 2004None

Swing

public class Swing extends JComponent
Template standalone Swing GUI application.
author
Ian Darwin, http://www.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);