package Test7_1;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Register extends JFrame
{
public Register()
{
setBounds(300,300,300,300);
setVisible(true);
setTitle("登录窗口");
Container c=getContentPane();
JLabel id1=new JLabel("用户名");
JLabel key1=new JLabel("密 码");
JTextField id2=new JTextField(15);
JPasswordField key2=new JPasswordField(15);
key2.setEchoChar('*');
JButton confirm=new JButton("确认");
JButton cancle=new JButton("取消");
c.add(id1);
c.add(key1);
c.add(id2);
c.add(key2);
c.add(confirm);
c.add(cancle);
id1.setBounds(10,40,50,20);
key1.setBounds(10,80,50,20);
id2.setBounds(60,40,200,20);
key2.setBounds(60,80,200,20);
confirm.setBounds(30,120,60,30);
cancle.setBounds(190,120,60,30);
confirm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(id2.getText().trim().equals("admin")&&new String(key2.getPassword()).equals("1234"))
{
new Enter();
}
else
{
JOptionPane.showMessageDialog(null,"用户名密码错误,请重新输入");
id2.setText("");
key2.setText("");
}
}
});
cancle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
public static void main(String args[])
{
new Register();
}
}
package Test7_1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Enter extends JFrame {
Enter() {
setBounds(100,100,500,400);
setTitle("学生信息录入窗口");
Container c = getContentPane();
setVisible(true);
setAlwaysOnTop(true);
c.setLayout(null);
JLabel id = new JLabel("学号");
JLabel name = new JLabel("姓名");
JLabel sex = new JLabel("性别");
JRadioButton mm = new JRadioButton("男");
JRadioButton fm = new JRadioButton("女");
JLabel date = new JLabel("出生日期");
JLabel member = new JLabel("团员");
JCheckBox member1 = new JCheckBox();
JLabel profession = new JLabel("专业");
String str[] = {"计算机", "自动化", "电子信息"};
JComboBox profession1 = new JComboBox(str);
JLabel address = new JLabel("家庭地址");
JLabel resume = new JLabel("简历");
JTextArea resume1=new JTextArea(20,30);
JButton save = new JButton("保存");
JButton cancel = new JButton("取消");
JTextField id1 = new JTextField(15);
JTextField name1 = new JTextField(15);
JTextField date1 = new JTextField(15);
JTextField address1 = new JTextField(15);
c.add(id);
c.add(id1);
c.add(name);
c.add(name1);
c.add(sex);
c.add(mm);
c.add(fm);
c.add(member);
c.add(member1);
c.add(profession);
c.add(profession1);
c.add(date);
c.add(date1);
c.add(address);
c.add(address1);
c.add(resume);
c.add(resume1);
c.add(save);
c.add(cancel);
id.setBounds(20, 40, 50, 18);
id1.setBounds(70, 40, 80, 18);
name.setBounds(20, 60, 50, 18);
name1.setBounds(70, 60, 80, 18);
sex.setBounds(20, 80, 50, 18);
mm.setBounds(80, 80, 50, 18);
fm.setBounds(140, 80, 50, 18);
member.setBounds(20, 100, 50, 18);
member1.setBounds(70, 100, 20, 18);
profession.setBounds(20, 120, 50, 18);
profession1.setBounds(80, 120, 100, 18);
date.setBounds(20, 140, 60, 18);
date1.setBounds(90,140,80,18);
address.setBounds(20,160,80,18);
address1.setBounds(110,160,150,18);
resume.setBounds(20,180,50,18);
resume1.setBounds(80,180,250,120);
save.setBounds(20,320,80,18);
cancel.setBounds(110,320,80,18);
save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resume1.setText("");
String id=id1.getText();
resume1.append("学生学号为:"+id+"\n");
String name=name1.getText();
resume1.append("学生姓名为:"+name+"\n");
if(mm.isSelected())
resume1.append("学生性别为男\n");
else
resume1.append("学生性别为女\n");
String date=date1.getText();
resume1.append("学生姓名为:"+date+"\n");
if(member1.isSelected())
{
resume1.append("是否是团员:是\n");
}
else
resume1.append("是否是团员:否\n");
String profession=profession1.getSelectedItem().toString();
resume1.append("专业为:"+profession+"\n");
String address=address1.getText();
resume1.append("家庭地址:"+address+"\n");
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
}
笨方法仅供参考