FileDocCategorySizeDatePackage
AnonymousDemo.javaAPI DocExample4839Sun Dec 14 22:47:38 GMT 2003oreilly.hcj.nested

AnonymousDemo

public class AnonymousDemo extends JDialog
Demonstrates anonymous classes.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.6 $

Fields Summary
private static final Logger
LOGGER
The logging object
private static final ImageIcon
LOGO
Holds the logo image
private static final String
LOGO_LOCATION
Holds the location of the logo image.
private final Container
contentPane
Holds a reference to the content pane.
private String
demo
holds a demo variable.
Constructors Summary
public AnonymousDemo()
Creates a new AnonymousDemo object.


	      	 
	  
		super();
		setTitle("Anonymous Demo");
		setModal(true);
		contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		JLabel logoLabel = new JLabel(LOGO);
		contentPane.add(BorderLayout.NORTH, logoLabel);

		JButton btn = new JButton("Beep");
		btn.addActionListener(new ActionListener() {
				public void actionPerformed(final ActionEvent event) {
					Toolkit.getDefaultToolkit()
					       .beep();
				}
			});
		contentPane.add(BorderLayout.SOUTH, btn);
		pack();
	
public AnonymousDemo(int exitDelay)
Creates a new AnonymousDemo object.

param
exitDelay The delay before exiting.
throws
RuntimeException If there is a runtime problem.

		super();
		setTitle("Anonymous Demo");
		setModal(true);
		contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		final String delayDisplay =
			new Object() {
					public String toString() {
						System.out.println(demo);
						if ((exitDelay) > 1000) {
							// Show in seconds. 
							NumberFormat formatter = NumberFormat.getNumberInstance();
							formatter.setMinimumFractionDigits(2);
							double time = exitDelay / 1000.0;
							return (new String(formatter.format(time) + " seconds"));
						} else {
							// Show in Microseconds
							return new String(exitDelay + " microseconds");
						}
					}
				}.toString();

		addWindowListener(new WindowAdapter() {
				public void windowClosing(final WindowEvent event) {
					try {
						System.out.println("Waiting for " + delayDisplay);
						Thread.sleep(exitDelay);
					} catch (final InterruptedException ex) {
						throw new RuntimeException(ex);
					}
				}
			});

		JLabel logoLabel = new JLabel(LOGO);
		contentPane.add(BorderLayout.NORTH, logoLabel);

		JButton btn =
			new JButton("Beep") {
				public void fireActionPerformed(final ActionEvent event) {
					if (LOGGER.isDebugEnabled()) {
						LOGGER.debug(event);
						LOGGER.debug("This class is: " + this.getClass().getName());
					}
					super.fireActionPerformed(event);
				}
			};

		btn.addActionListener(new ActionListener() {
				public void actionPerformed(final ActionEvent event) {
					doBeep();
				}
			});
		contentPane.add(BorderLayout.SOUTH, btn);

		pack();
	
Methods Summary
private voiddoBeep()
DOCUMENT ME!

		Toolkit.getDefaultToolkit()
		       .beep();
	
public java.lang.StringgetDemo()
Getter for the property demo.

return
The current value of demo.

		return demo;
	
public static final voidmain(java.lang.String[] args)
Run the demo

param
args Command Line Arguments.

		AnonymousDemo demo = new AnonymousDemo(1450);
		demo.show();
		System.out.println("Done");
		System.exit(0);
	
public voidsetDemo(java.lang.String demo)
Setter for the property demo.

param
demo The new value for demo.

		this.demo = demo;