1, a shown in FIG production interface (using FlowLayout layout), does not achieve required functions.
. 1 Package sixth training; 2 . 3 Import in javax.swing *. ; . 4 . 5 public class of MyFrame { . 6 the JFrame F; . 7 the JLabel L1, L2, L3, L4, La, LB, LC, LD; . 8 the JPanel P; . 9 the JTextField T1, T2, T3, TA, TB, TC; 10 the JButton B1, B2; . 11 public of MyFrame () { 12 is 13 is F = new new the JFrame (); 14 L1 = new new the JLabel ( "current time:" ); 15 P = new new the JPanel (); 16 L2 = new new the JLabel ( "when" ); . 17 P = new new the JPanel (); 18 is L3 = new new the JLabel ( "points" ); . 19 P = new new the JPanel (); 20 is L4 = new new the JLabel ( "second" ); 21 is T1 = new new the JTextField (. 4 ); 22 is T2 = new new the JTextField (. 4 ); 23 is T3 = new new the JTextField (. 4 ); 24 25 La = new new the JLabel ( "alarm time:" ); 26 p=new JPanel(); 27 lb=new JLabel("时"); 28 p=new JPanel(); 29 lc=new JLabel("分"); 30 p=new JPanel(); 31 ld=new JLabel("秒"); 32 ta=new JTextField(4); 33 tb=new JTextField(4); 34 tc=new JTextField(4); 35 36 b1=new JButton("开"); 37 b2=new JButton("关"); 38 39 p.add(l1); 40 p.add(t1); 41 f.add(p); 42 p.add(l2); 43 p.add(t2); 44 f.add(p); 45 p.add(l3); 46 p.add(t3); 47 p.add(l4); 48 f.add(p); 49 50 51 p.add(la); 52 p.add(ta); 53 f.add(p); 54 p.add(lb); 55 p.add(tb); 56 f.add(p); 57 p.add(lc); 58 p.add(tc); 59 p.add(ld); 60 f.add(p); 61 62 p.add(b1); 63 p.add(b2); 64 65 f.setSize(300,200); 66 f.setVisible(true); 67 68 } 69 public static void main(String[] args){ 70 new MyFrame(); 71 } 72 }
2 designing a label, a line of text and button login interface (using GridLayout layout). as the picture shows.
1 package 第六次实训; 2 import java.awt.GridLayout; 3 4 import javax.swing.*; 5 6 public class aaa{ 7 JFrame f; 8 JLabel l1,l2; 9 JPanel p; 10 JTextField t1,t2; 11 JButton b1,b2; 12 public aaa(){ 13 14 f=new JFrame(); 15 l1=new JLabel("用户名:"); 16 p=new JPanel(); 17 t1=new JTextField(3); 18 19 l2=new JLabel("口令:"); 20 p=new JPanel(); 21 t2=new JTextField(3); 22 23 b1=new JButton("确定"); 24 b2=new JButton("取消"); 25 26 p.setLayout(new GridLayout(3,2)); 27 28 p.add(l1); 29 p.add(t1); 30 f.add(p); 31 32 p.add(l2); 33 p.add(t2); 34 f.add(p); 35 36 p.add(b1); 37 p.add(b2); 38 39 f.setSize(250,150); 40 f.setVisible(true); 41 42 } 43 public static void main(String[] args){ 44 new aaa(); 45 } 46 }