packageLibrarySystem;importjava.awt.Color;importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.GridLayout;importjava.awt.Window;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.awt.event.WindowListener;importjavax.swing.ButtonGroup;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JRadioButton;importjavax.swing.JTextField;importjavax.swing.WindowConstants;public class LSLogin extendsJFrame {public static voidmain(String[] args) {newLSLogin();
}publicLSLogin() {
setTitle("图书馆管理系统");
Container con=getContentPane();
setLayout(null);/*------------标题奥设置--------------------*/JLabel jl1= new JLabel("图书馆管理系统");
jl1.setBounds(450, 40, 110, 30);//jl1.setSize(100, 30);
jl1.setBackground(Color.DARK_GRAY);
con.add(jl1);/*-----------账号设置--------------*/JPanel jp2= newJPanel();
jp2.setLayout(newFlowLayout());
JLabel jl2= new JLabel("账号");
JTextField jtf2= new JTextField(14);
jp2.add(jl2);
jp2.add(jtf2);
jp2.setBounds(150, 110, 270, 40);
con.add(jp2);/*--------------密码设置----------------*/JPanel jp3= newJPanel();
jp3.setLayout(newFlowLayout());
JLabel jl3= new JLabel("密码");
JPasswordField jpf3= new JPasswordField(14);
jpf3.setEchoChar('*');
jp3.add(jl3);
jp3.add(jpf3);
jp3.setBounds(150, 150, 270, 40);
con.add(jp3);/*----------------用户身份----------------------*/JPanel jp4= newJPanel();
ButtonGroup bg4= newButtonGroup();
jp4.setLayout(new GridLayout(1, 3, 5, 0));
String identity[]= new String[] { "管理员", "教师", "学生"};for (int i = 0; i < identity.length; i++) {//JCheckBox jcb4 = new JCheckBox(identity[i]);
JRadioButton rb4 = newJRadioButton(identity[i]);
bg4.add(rb4);
jp4.add(rb4);
}
jp4.setBounds(200, 220, 220, 40);
con.add(jp4);/*-----------------两个button 登陆 注册设置---------*/JPanel jp5= newJPanel();
JButton jb5a= new JButton("登陆");
JButton jb5b= new JButton("注册");
jp5.add(jb5a);
jp5.add(jb5b);
jp5.setBounds(140, 290, 300, 40);
con.add(jp5);/*** 为注册设置监听事件*/jb5b.addActionListener(newActionListener() {
@Overridepublic voidactionPerformed(ActionEvent arg0) {//TODO Auto-generated method stub
new Register().RDemo("注册界面");
}
});/*-----------------窗体界面设置---------------*/setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(400, 0, 600, 400);
setBackground(Color.cyan);
addWindowListener(newWindowAdapter() {public voidWindowClosing(WindowEvent e) {//this.dispose();
}
});
}
}class Register extendsJFrame {
String Sinfer[]= new String[] { "姓名", "密码", "年龄", "性别", "联系方式", "所在学院"};
String Minfer[]= new String[] { "姓名", "密码", "年龄", "性别", "联系方式", "家庭住址"};privateJLabel jl1;privateJLabel jl2;privateJTextField jtf;privateJTextField jtf2;private JPanel jp = new JPanel(new GridLayout(Sinfer.length, 2, 0, 5));//学生注册界面小窗体设置
private JPanel jp2 = new JPanel(new GridLayout(Minfer.length, 2, 0, 5));//管理员注册界面小窗体设置
privateJButton jb;public voidRDemo(String title) {
setTitle(title);final Container con =getContentPane();
setLayout(null);/*------------身份种类---------------*/JPanel jp1= newJPanel();
jp1.setLayout(newFlowLayout());
JButton jb1a= new JButton("借书者注册");
JButton jb1b= new JButton("管理员注册");
jp1.add(jb1a);
jp1.add(jb1b);
jp1.setBounds(25, 10, 300, 35);
con.add(jp1);/*-----------------学生注册信息设置-----------*/jb1a.addActionListener(newActionListener() {
@Overridepublic voidactionPerformed(ActionEvent arg0) {//TODO Auto-generated method stub
for (int i = 0; i < Sinfer.length; i++) {
jl1= newJLabel(Sinfer[i]);
jtf= new JTextField(16);
jp.add(jl1);
jp.add(jtf);
}
jp.setBounds(55, 60, 240, 250);
con.add(jp);
}
});/*--------------管理员注册信息设置-----------------*/jb1b.addActionListener(newActionListener() {
@Overridepublic voidactionPerformed(ActionEvent arg0) {//TODO Auto-generated method stub
for (int i = 0; i < Minfer.length; i++) {
jl2= newJLabel(Minfer[i]);
jtf2= new JTextField(16);
jp2.add(jl2);
jp2.add(jtf2);
}
jp2.setBounds(55, 60, 240, 250);
con.add(jp2);
}
});/*---------确定button------------*/jb= new JButton("确定");
jb.setBounds(135, 320, 80, 30);
con.add(jb);/*为确定按钮添加监听事件*/jb.addActionListener(newActionListener() {
@Overridepublic voidactionPerformed(ActionEvent arg0) {//TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "保存完成");
}
});/*-------------窗体设置*/setVisible(true);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.addWindowListener(newWindowAdapter() {public voidwindowClosing(WindowEvent e) {//this.dispose();//释放当前窗口资源,并且设置为不可见 } });
}
});
setBounds(800, 100, 350, 450);
}
}