1 package jframe; 2 3 import java.awt.*; 4 import javax.swing.*; 5 6 public class JPanel7 extends JFrame{ 7 //標籤數組,長度爲5 8 JLabel[] lb = {null,null,null,null,null}; 9 //面板數組,長度爲4 10 JPanel[] pn = {null,null,null,null}; 11 //選項卡,直接添加三個面板 12 JTabbedPane tbp; 13 //文本框 14 JTextField tf; 15 //密碼框 16 JPasswordField pf; 17 //按鈕 18 JButton[] bt = {null,null,null,null}; 19 //複選框 20 JCheckBox[] cb = {null,null}; 21 //構造方法 22 public JPanel7(){ 23 //標籤,內容爲圖片 24 lb[0] = new JLabel(new ImageIcon("images/top.png")); 25 //標籤,內容爲文本,文本垂直居中對其; 26 lb[1] = new JLabel("帳號",JLabel.CENTER); 27 lb[2] = new JLabel("密碼",JLabel.CENTER); 28 //標籤,內容爲超連接 29 lb[3] = new JLabel("<html><a href='www.qq.com'>忘記密碼</a>",JLabel.CENTER); 30 //標籤字體,:普通樣式常量,字號; 31 //BOLD :粗體樣式常量 ,ITALIC: 斜體樣式常量 32 lb[3].setFont(new Font("宋體",Font.PLAIN,16)); 33 //前景色 34 lb[3].setForeground(Color.BLUE); 35 //光標預設 36 lb[3].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 37 lb[4] = new JLabel("<html><a href='www.qq.com'>申請密碼保護</a>"); 38 lb[4].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 39 tf = new JTextField(10); 40 pf = new JPasswordField(10); 41 cb[0] = new JCheckBox("隱身登陸"); 42 cb[1] = new JCheckBox("記住密碼"); 43 bt[0] = new JButton("清除密碼"); 44 bt[1] = new JButton("登陸"); 45 bt[2] = new JButton("取消"); 46 bt[3] = new JButton("申請帳號"); 47 // bt[3] = new JButton(new ImageIcon("images/readme.png")); 48 49 //普通登陸面板 50 pn[0] = new JPanel(); 51 //會員登陸面板 52 pn[1] = new JPanel(); 53 //管理員登陸面板 54 pn[2] = new JPanel(); 55 //BorderLayout。south。面板 56 pn[3] = new JPanel(); 57 //選項卡 58 tbp = new JTabbedPane(); 59 //網格佈局 60 pn[0].setLayout(new GridLayout(3,3)); 61 //添加組件 62 pn[0].add(lb[1]); 63 pn[0].add(tf); 64 pn[0].add(bt[0]); 65 pn[0].add(lb[2]); 66 pn[0].add(pf); 67 pn[0].add(lb[3]); 68 pn[0].add(cb[0]); 69 pn[0].add(cb[1]); 70 pn[0].add(lb[4]); 71 72 pn[3].add(bt[1]); 73 pn[3].add(bt[2]); 74 pn[3].add(bt[3]); 75 76 //將面板加至選項卡 77 tbp.add("普通用戶",pn[0]); 78 tbp.add("會員登陸",pn[1]); 79 tbp.add("管理員",pn[2]); 80 81 //設置容器佈局 82 this.add(lb[0],BorderLayout.NORTH); 83 this.add(tbp,BorderLayout.CENTER); 84 this.add(pn[3],BorderLayout.SOUTH); 85 86 this.setIconImage((new ImageIcon("images/icon.png")).getImage()); 87 this.setTitle("梁孟源10"); 88 this.setSize(428,350); 89 this.setLocation(400,100); 90 this.setResizable(false); 91 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 92 this.setVisible(true); 93 } 94 public static void main(String[] args){ 95 new JPanel7(); 96 } 97 }