FileDocCategorySizeDatePackage
MethodInnerClassDemo.javaAPI DocExample4461Sun Dec 14 22:47:32 GMT 2003oreilly.hcj.nested

MethodInnerClassDemo

public class MethodInnerClassDemo extends JDialog
Demonstrates method-scoped inner classes.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.6 $

Fields Summary
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 MethodInnerClassDemo(int value)
Creates a new MethodInnerClassDemo object.

param
value Some value to be used.

		super();
		String title = "Inner Class Demo";
		setTitle(title);
		setModal(true);
		contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

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

		JButton btn = new JButton("Beep");

		/**  
		 * An action listener class.
		 *
		 * @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
		 * @version $Revision: 1.6 $
		 */
		class MyActionListener implements ActionListener {
			/** 
			 * {@inheritDoc}
			 */
			public void actionPerformed(final ActionEvent event) {
				Toolkit.getDefaultToolkit()
				       .beep();
				System.out.println(value);
				System.out.println(MethodInnerClassDemo.LOGO_LOCATION);
				System.out.println(MethodInnerClassDemo.this.demo);
				// System.out.println(title); // <= compiler error
			}
		}
		btn.addActionListener(new MyActionListener());

		contentPane.add(BorderLayout.SOUTH, btn);
		pack();
	
public MethodInnerClassDemo()
Creates a new MethodInnerClassDemo object.

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

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

		JButton btn1 = new JButton("Beep");
		JButton btn2 = new JButton("Bell");

		/**  
		 * An action listener class.
		 *
		 * @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
		 * @version $Revision: 1.6 $
		 */
		class MyActionListener implements ActionListener {
			/** 
			 * {@inheritDoc}
			 */
			public void actionPerformed(final ActionEvent event) {
				Toolkit.getDefaultToolkit()
				       .beep();
			}
		}
		btn1.addActionListener(new MyActionListener());
		btn2.addActionListener(new MyActionListener());

		JPanel pnl = new JPanel(new GridLayout(1, 2));
		pnl.add(btn1);
		pnl.add(btn2);

		contentPane.add(BorderLayout.SOUTH, pnl);
		pack();
	
Methods Summary
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.

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

param
demo The new value for demo.

		this.demo = demo;
	
public voidsomeMethod()
Some demo method.

		// ActionListener listener = new MyActionListener(); // <= compiler error.