标签:style blog color io ar java sp div 2014
1
Frame
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 Frame f = new Frame("my first frame;"); 10 f.setSize(190, 200); 11 f.setBackground(Color.blue); 12 f.setLocation(100, 200); //设置窗口出现的位置,默认0,0 13 f.setResizable(true); //设置是否可以改变大小,默认可以 14 f.setVisible(true); //使窗口可见 15 } 16 }
2
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 w a = new w("wori", 199, 199, Color.BLACK, false, true); 10 } 11 } 12 13 class w extends Frame 14 { 15 w(String n, int a, int b, Color c, boolean d, boolean e) 16 { 17 super(n); 18 setSize(a, b); 19 setBackground(c); 20 setResizable(d); 21 setVisible(e); 22 } 23 }
3
setBounds(x, y ,a, b) 设置位置,高宽
4
Panel
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 Frame f= new Frame("wori"); 10 f.setLayout(null); 11 f.setBounds(0, 0, 400, 400); 12 f.setBackground(Color.GRAY); 13 Panel p = new Panel(null); //不可以单独出现,必须嵌套进Frame里,可以互相嵌套 14 p.setBounds(50, 50, 100, 100); 15 p.setBackground(Color.cyan); 16 f.setResizable(true); 17 f.setVisible(true); 18 f.add(p); 19 20 } 21 }
5
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 new w("wori", 100, 100, 200, 200, Color.black, Color.yellow); 10 } 11 } 12 13 class w extends Frame 14 { 15 private Panel p = null; 16 w(String n, int a, int b, int c, int d, Color e, Color f) 17 { 18 super(n); 19 setBackground(e); 20 setBounds(a, b, c, d); 21 setLayout(null); 22 p = new Panel(null); 23 p.setBackground(f); 24 p.setBounds(a/2, b/2, c/2, d/2); 25 add(p); 26 setVisible(true); 27 } 28 }
6
FlowLayout
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 Frame f = new Frame("wori"); 10 f.setBounds(100, 100, 50, 50); 11 Button a = new Button("a"); 12 Button b = new Button("b"); 13 Button c = new Button("c"); 14 f.setLayout(new FlowLayout(FlowLayout.LEFT, 20, 40)); //ppt 15 f.add(a); 16 f.add(b); 17 f.add(c); 18 f.setVisible(true); 19 } 20 } 21 22 class w extends Frame 23 { 24 private Panel p = null; 25 w(String n, int a, int b, int c, int d, Color e, Color f) 26 { 27 super(n); 28 setBackground(e); 29 setBounds(a, b, c, d); 30 setLayout(null); 31 p = new Panel(null); 32 p.setBackground(f); 33 p.setBounds(a/2, b/2, c/2, d/2); 34 add(p); 35 setVisible(true); 36 } 37 }
7
BorderLayout
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 Frame f = new Frame("wori"); 10 f.setBounds(100, 100, 50, 50); 11 Button a = new Button("a"); 12 Button b = new Button("b"); 13 Button c = new Button("c"); 14 Button d = new Button("d"); 15 Button e = new Button("e"); 16 f.add(a, BorderLayout.NORTH); //Frame默认布局管理器 17 f.add(b, "West"); //另一种方式 18 f.add(c, BorderLayout.EAST); 19 f.setVisible(true); 20 21 } 22 }
8
GridLayout
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 Frame f = new Frame("wori"); 10 Button a = new Button("a"); 11 Button b = new Button("b"); 12 Button c = new Button("c"); 13 Button d = new Button("d"); 14 Button e = new Button("e"); 15 f.setLayout(new GridLayout(3, 2)); //将Frame分割成3行2列 16 f.add(a); 17 f.add(b); 18 f.add(c); 19 f.add(d); 20 f.add(e); 21 f.pack(); //窗口将设置成包着按钮的大小 22 f.setVisible(true); 23 24 } 25 }
9
1 package hello; 2 import java.awt.*; 3 import java.io.*; 4 import java.net.*; 5 public class helloworld 6 { 7 public static void main(String[] args)throws Exception 8 { 9 Frame f = new Frame("wori"); 10 f.setBounds(100, 100, 500, 500); 11 Button b = new Button("a"); 12 Button c = new Button("c"); 13 Panel p = new Panel(); 14 Panel q = new Panel(); 15 p.add(b, BorderLayout.CENTER); 16 q.add(c, BorderLayout.WEST); 17 p.add(q); 18 f.add(p); 19 f.setVisible(true); 20 21 } 22 }
Frame,Panel可以嵌套
标签:style blog color io ar java sp div 2014
原文地址:http://www.cnblogs.com/melon2014/p/4004823.html