📄 学生信息管理系统
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Student extends WindowAdapter implements ActionListener,ItemListener
{
//变量定义
private Choice m_year, m_month,m_day;
private Button button1,button2; //录入,清除
private Checkbox box1,box2,box3,box4;
private TextArea ta;
Frame f;
TextField f1,f2;
CheckboxGroup sex,unite;
//按钮事件监听
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
ta.append('\n'+f1.getText()+" "+f2.getText()
+" "+sex.getSelectedCheckbox().getLabel()
+" "+(m_year.getSelectedIndex()+1975)+"年"
+(m_month.getSelectedIndex()+1)+"月"
+(m_day.getSelectedIndex()+1)+"日"
+" "+unite.getSelectedCheckbox().getLabel());
try{
FileWriter fout=new FileWriter("白.txt"); //输出到文件中保存
fout.write(ta.getText());
fout.close();
}
catch(IOException we){}
}
else if(e.getSource()==button2)
{
f1.setText("");
f2.setText("");
}
}
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
//月份处理函数
public void itemStateChanged(ItemEvent e){
int month = m_month.getSelectedIndex();
int year = m_year.getSelectedIndex()+1975;
int i,ik = 0;
m_day.removeAll();
switch(month+1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ik=31;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0) { ik=29;}
else ik=28;
break;
case 4:
case 6:
case 9:
case 11:
ik=30;
default:
}
for(i=1;i<=ik;i++)
{
m_day.add(i+"日");
}
}
//创建控件
public void Create()
{
int i;
f=new Frame("学生信息系统");
sex=new CheckboxGroup();
unite=new CheckboxGroup();
m_year=new Choice();
m_month=new Choice();
m_day=new Choice();
for(i=1975;i<=1990;i++)
{
m_year.add(i+"年");
}
for(i=1;i<=12;i++)
{
m_month.add(i+"月");
}
for(i=1;i<=31;i++)
{
m_day.add(i+"日");
}
m_month.addItemListener(this);
m_year.addItemListener(this);
box1 = new Checkbox("男",true,sex);
box2 = new Checkbox("女",false,sex);
box3 = new Checkbox("联合培养",true,unite);
box4 = new Checkbox("不联合培养",false,unite);
f1 = new TextField(6);
f2 = new TextField(6);
Panel pan1 = new Panel();
Panel pan2 = new Panel();
Panel pan3 = new Panel();
Panel pan4 = new Panel();
Label l1 = new Label("姓名");
Label l2 = new Label("学号");
Label l3 = new Label("出生日期");
Label l4 = new Label("性别");
button1 = new Button("录入");
button2 = new Button("清除");
ta=new TextArea();
f.setBackground(Color.gray);
f.setLayout(new FlowLayout(FlowLayout.LEFT,20,30));
pan1.setLayout(new GridLayout(1,2,5,8));
pan1.add(l1);
pan1.add(f1);
pan1.add(l2);
pan1.add(f2);
pan3.add(l3);
pan3.add(m_year);
pan3.add(m_month);
pan3.add(m_day);
pan2.add(box3);
pan2.add(box4);
pan2.add(l4);
pan2.add(box1);
pan2.add(box2);
f.add(pan1);
f.add(pan2);
f.add(pan3);
pan4.add(button1);
pan4.add(button2);
f.add(pan4);
f.add(ta);
button1.addActionListener(this);
button2.addActionListener(this);
f.addWindowListener(this);
f.setSize(500,500);
f.setVisible(true);
}
public static void main(String args[])
{
Student students=new Student();
students.Create();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -