JAVA-绘制窗口例子

 
  
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 }

转载于:https://www.cnblogs.com/binbinjava/archive/2011/04/17/2019064.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值