public class InnerClassDemo extends JFrame
1:
2: import javax.swing.*;
3: import java.awt.*;
4: import java.awt.event.*;
5:
6: public class InnerClassDemo extends JFrame
7: {
8: public static final int WIDTH = 300;
9: public static final int HEIGHT = 200;
10:
11: /**
12: Creates and displays a window of the class InnerClassDemo.
13: */
14: public static void main(String[] args)
15: {
16: InnerClassDemo sampleGUI = new InnerClassDemo( );
17: sampleGUI.setVisible(true);
18: }
19:
20: public InnerClassDemo( )
21: {
22: setSize(WIDTH, HEIGHT);
23: setTitle("Inner Class Demo");
24: Container contentPane = getContentPane( );
25: contentPane.setLayout(new BorderLayout( ));
26:
27: JLabel label = new JLabel(
28: "Please don't click that button!");
29: contentPane.add(label, BorderLayout.CENTER);
30:
31: addWindowListener(new InnerDestroyer( ));
32: }
33:
34: //An inner class with the same functionality
35: //as the class WindowDestroyer.
36: private class InnerDestroyer extends WindowAdapter
37: {
38: public void windowClosing(WindowEvent e)
39: {
40: System.exit(0);
41: }
42: }
43: }