1
/*
2 * JAVA中弹出窗口例子
3 * 类结构
4 * -JComponent-JPanel
5 * Object-Component-Container |
6 * -Window-Frame-JFrame
7 */
8 import javax.swing. * ;
9 import java.awt. * ;
10 public class NotHelloWorld {
11 public static void main(String[] args)
12 {
13 EventQueue.invokeLater( new Runnable()
14 {
15 public void run()
16 {
17 NotHelloWorldFrame frame = new NotHelloWorldFrame();
18 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19 frame.setVisible( true );
20 }
21 });
22 }
23
24 }
25 /*
26 A frame that contains amessage panel
27 */
28 class NotHelloWorldFrame extends JFrame
29 {
30 public NotHelloWorldFrame()
31 {
32 setTitle( " NotAHelloWorld " );
33 setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
34 // add panel to frame
35 NotHelloWorldPanel panel = new NotHelloWorldPanel();
36 add(panel);
37 }
38 public static final int DEFAULT_WIDTH = 300 ;
39 public static final int DEFAULT_HEIGHT = 200 ;
40 }
41 /*
42 * A panel that displays a message
43 */
44 class NotHelloWorldPanel extends JPanel
45 {
46 public void paintComponent(Graphics g)
47 {
48 g.drawString( " NotHelloWorld is not a hello World! " , MESSAGE_X, MESSAGE_Y);
49 }
50 public static final int MESSAGE_X = 50 ;
51 public static final int MESSAGE_Y = 75 ;
52 }
2 * JAVA中弹出窗口例子
3 * 类结构
4 * -JComponent-JPanel
5 * Object-Component-Container |
6 * -Window-Frame-JFrame
7 */
8 import javax.swing. * ;
9 import java.awt. * ;
10 public class NotHelloWorld {
11 public static void main(String[] args)
12 {
13 EventQueue.invokeLater( new Runnable()
14 {
15 public void run()
16 {
17 NotHelloWorldFrame frame = new NotHelloWorldFrame();
18 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19 frame.setVisible( true );
20 }
21 });
22 }
23
24 }
25 /*
26 A frame that contains amessage panel
27 */
28 class NotHelloWorldFrame extends JFrame
29 {
30 public NotHelloWorldFrame()
31 {
32 setTitle( " NotAHelloWorld " );
33 setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
34 // add panel to frame
35 NotHelloWorldPanel panel = new NotHelloWorldPanel();
36 add(panel);
37 }
38 public static final int DEFAULT_WIDTH = 300 ;
39 public static final int DEFAULT_HEIGHT = 200 ;
40 }
41 /*
42 * A panel that displays a message
43 */
44 class NotHelloWorldPanel extends JPanel
45 {
46 public void paintComponent(Graphics g)
47 {
48 g.drawString( " NotHelloWorld is not a hello World! " , MESSAGE_X, MESSAGE_Y);
49 }
50 public static final int MESSAGE_X = 50 ;
51 public static final int MESSAGE_Y = 75 ;
52 }