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 }