码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA_GUI_初步

时间:2015-05-17 23:17:11      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

技术分享

 

技术分享

 

技术分享

 

 1 /*    范例名称:Frame 应用举例
 2  *     源文件名称:TestFrame.java
 3  *    要  点:Frame组件的创建及显示设置
 4  */
 5 
 6 import java.awt.*;
 7 public class TestFrame {
 8     public static void main( String args[]) {
 9         Frame f = new Frame("My First Test");
10         f.setLocation(500, 200);
11         f.setSize( 170,100);
12         f.setBackground( Color.green);
13         f.setResizable(true);
14         f.setVisible( true);
15     }
16 }

 

 1 import java.awt.*;
 2 
 3 public class TestMultiFrame {
 4     public static void main(String args[]) {
 5         MyFrame f1 = 
 6             new MyFrame(100,100,200,200,Color.BLUE);
 7         MyFrame f2 = 
 8             new MyFrame(300,100,200,200,Color.YELLOW);
 9         MyFrame f3 = 
10             new MyFrame(100,300,200,200,Color.GREEN);
11         MyFrame f4 = 
12             new MyFrame(300,300,200,200,Color.MAGENTA);
13     }
14 }
15 
16 
17 
18 
19 class MyFrame extends Frame{
20     static int id = 0;
21     MyFrame(int x,int y,int w,int h,Color color){
22         super("MyFrame " + (++id));
23         setBackground(color);
24         setLayout(null);
25         setBounds(x,y,w,h);
26         setVisible(true);
27     }
28 }

 

技术分享

 

 1 import java.awt.*;
 2 
 3 public class TestPanel {
 4      public static void main(String args[]) {
 5               Frame f = 
 6              new Frame("Java Frame with Panel");
 7          Panel p = new Panel(null);
 8          f.setLayout(null);
 9          f.setBounds(300,300,500,500);
10          f.setBackground(new Color(0,0,102));
11          p.setBounds(50,50,400,400);
12          p.setBackground(new Color(204,204,255));
13          f.add(p);
14          f.setVisible(true);
15     }
16 }

 

 1 import java.awt.*;
 2 
 3 public class TestMultiPanel {
 4     public static void main(String args[]) {
 5         new MyFrame2("MyFrameWithPanel",300,300,400,300);
 6     }
 7 }
 8 
 9 
10 class MyFrame2 extends Frame{
11     private Panel p1,p2,p3,p4;
12     MyFrame2(String s,int x,int y,int w,int h){
13         super(s);
14         setLayout(null);
15         p1 = new Panel(null); p2 = new Panel(null);
16         p3 = new Panel(null); p4 = new Panel(null);
17         p1.setBounds(0,0,w/2,h/2);
18         p2.setBounds(0,h/2,w/2,h/2);
19         p3.setBounds(w/2,0,w/2,h/2);
20         p4.setBounds(w/2,h/2,w/2,h/2);
21         p1.setBackground(Color.BLUE);
22         p2.setBackground(Color.GREEN);
23         p3.setBackground(Color.YELLOW);
24         p4.setBackground(Color.MAGENTA);
25         add(p1);add(p2);add(p3);add(p4);
26         setBounds(x,y,w,h);
27         setVisible(true);
28     }
29 }

 

JAVA_GUI_初步

标签:

原文地址:http://www.cnblogs.com/roger-h/p/4510591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!