1.需求分析
功能要求:
1)需要管理的学生信息有:学号、姓名、性别、出生日期、政治面貌、家庭住址、电话、宿舍号。
2)实现查询、增、删、改等功能。
数据存储:数据库或文件。
2.本组课题及本人任务
本组的课题是学生信息管理系统,我负责的任务是完成学生信息管理系统的图形界面。
3.总体设计(概要设计)
本组完成的是学生信息管理系统,主要的功能有增,删,查,改,管理的学生信息有学号、姓名、性别、出生日期、政治面貌、家庭住址、电话、宿舍号。并且使用数据库来储存学生信息。
小组成员
翁华辉:负责完成学生信息管理系统的图形界面,
张雨阳:负责编写学生信息管理系统的增删改查。
具体代码:
登陆界面:
//给屏幕的宽度高度,程序窗口的宽度高度赋值
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
screenSizeWidth = (int) dimension.getWidth();
screenSizeHeight = (int) dimension.getHeight();
windowWidth = this.getWidth();
windowHeight = this.getHeight();
//设置程序窗口的位置为屏幕的正中央
this.setLocation(screenSizeWidth / 2 - windowWidth / 2, screenSizeHeight / 2 - windowHeight / 2);
// 声明姓名,密码的标签
JLabel username_label = new JLabel("User:");
JLabel password_label = new JLabel("Password: ");
JLabel administrator_label = new JLabel("管理员登陆");
// 声明姓名输入框和密码输入框
final JTextField user_field = new JTextField();
final JPasswordField password_field = new JPasswordField();
//声明登录按钮
JButton login_btn = new JButton("登录");
JButton exit_btn = new JButton("退出");
//设置各个标签和输入框的大小和位置
username_label.setBounds(110, 100, 150, 50);
password_label.setBounds(110, 200, 150, 50);
administrator_label.setBounds(280, 50, 100, 50); //280, 60, 100, 30
user_field.setBounds(180, 100, 300, 50);
password_field.setBounds(180, 200, 300, 50);
login_btn.setBounds(200, 300, 100, 50);
exit_btn.setBounds(350, 300, 100, 50);
//添加到面板
this.add(username_label);
this.add(password_label);
this.add(user_field);
this.add(password_field);
this.add(login_btn);
this.add(exit_btn);
this.add(administrator_label);
登陆密码服务:
//登录按钮的监听器
login_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//当按钮被单击时自动调动这个方法
public void actionPerformed(ActionEvent event)
{
//如果用户名和密码都是123,那么弹出对话框显示登录成功,并且开启另一个主框架(主页)
if (user_field.getText().equals(userName)&& password_field.getText().equals(password))
{
JOptionPane.showMessageDialog(null, "登录成功", "Login",JOptionPane.INFORMATION_MESSAGE);
//声明主页
JFrame home_page = new JFrame("学生信息管理系统");
home_page.setResizable(false);
home_page.setSize(600, 600); //设置窗口的大小
home_page.setLayout(null); //设置程序默认布局格式为空,以便于后期自己简单的设置布局
home_page.setResizable(false); //设置不可缩放
//给主页设置位置
home_page.setLocation(screenSizeWidth / 2 - windowWidth / 2 + 50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//给主页设置大小
home_page.setSize(windowWidth, windowHeight);
//设置主页能够关闭,并且登录成功后将登录页面隐藏
home_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
home_page.setVisible(true);
setVisible(false);//登录页面隐藏
//功能选择界面
JLabel Menu_label = new JLabel("欢迎来到学生信息管理系统!!!");
//声明登录按钮
JButton write_btn = new JButton("1.添加学生信息");
JButton delate_btn = new JButton("2.删除学生信息");
JButton read_btn = new JButton("3.修改学生信息");
JButton display_btn = new JButton("4.查看学生信息");
JButton exit1_btn = new JButton("5.退出系统 ");
//设置各个标签和输入框的大小和位置
Menu_label.setBounds(200, 15, 300, 200);
write_btn.setBounds(200, 150, 150, 50);
delate_btn.setBounds(200, 200, 150, 50);
read_btn.setBounds(200, 250, 150, 50);
display_btn.setBounds(200, 300, 150, 50);
exit1_btn.setBounds(200, 350, 150, 50);
//添加到面板上
home_page.add(Menu_label);
home_page.add(write_btn);
home_page.add(delate_btn);
home_page.add(read_btn);
home_page.add(display_btn);
home_page.add(exit1_btn);
添加学生:
//添加学生信息按钮的监听器
write_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//当按钮被单击时自动调动这个方法
public void actionPerformed(ActionEvent event)
{
JFrame write_page = new JFrame("学生信息管理系统");
write_page.setResizable(false);
write_page.setSize(600, 600); //设置窗口的大小
write_page.setLayout(null); //设置程序默认布局格式为空,以便于后期自己简单的设置布局
write_page.setResizable(false); //设置不可缩放
//给主页设置位置
write_page.setLocation(screenSizeWidth/2- windowWidth/2+50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//给主页设置大小
write_page.setSize(windowWidth, windowHeight);
//设置主页能够关闭,并且登录成功后将登录页面隐藏
write_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
write_page.setVisible(true);
setVisible(false);//登录页面隐藏
//声明标签,按钮,
JLabel Menu1_label = new JLabel("添加学生信息");
JLabel Id1_label = new JLabel("ID");
JLabel name1_label = new JLabel("name");
JLabel gender1_label = new JLabel("gender");
JLabel birthDate1_label = new JLabel("birthDate");
JLabel politicalOutlook1_label = new JLabel("politicalOutlook");
JLabel familyLocate1_label = new JLabel("familyLocate");
JLabel phone1_label = new JLabel("phone");
JLabel dormitoryNum1_label = new JLabel("dormitoryNum");
final JTextField ID1_field = new JTextField();
final JTextField name1_field = new JTextField();
final JTextField gender1_field = new JTextField();
final JTextField birthDate1_field = new JTextField();
final JTextField politicalOutlook1_field = new JTextField();
final JTextField familyLocate1_field = new JTextField();
final JTextField phone1_field = new JTextField();
final JTextField dormitoryNum1_field = new JTextField();
JButton return1_btn = new JButton("返回");
JButton sure1_btn = new JButton("确定");
JButton exit2_btn = new JButton("退出系统");
//设置各个标签和输入框的大小和位置
Menu1_label.setBounds(250, 75, 100, 100);
Id1_label.setBounds(200, 150, 100, 50);
name1_label.setBounds(200, 190, 100, 50);
gender1_label.setBounds(200, 230, 100, 50);
birthDate1_label.setBounds(200, 270, 100, 50);
politicalOutlook1_label.setBounds(200, 310, 100, 50);
familyLocate1_label.setBounds(200, 350, 100, 50);
phone1_label.setBounds(200, 390, 100, 50);
dormitoryNum1_label.setBounds(200, 430, 100, 50);
ID1_field.setBounds(300, 160, 80, 25);
name1_field.setBounds(300, 200, 80, 25);
gender1_field.setBounds(300, 240, 80, 25);
birthDate1_field.setBounds(300, 280, 80, 25);
politicalOutlook1_field.setBounds(300, 320, 80, 25);
familyLocate1_field.setBounds(300, 360, 80, 25);
phone1_field.setBounds(300, 400, 80, 25);
dormitoryNum1_field.setBounds(300, 440, 80, 25);
return1_btn.setBounds(120, 500, 100, 50);
sure1_btn.setBounds(250, 500, 100, 50);
exit2_btn.setBounds(380, 500, 100, 50);
//添加到面板
write_page.add(Menu1_label);
write_page.add(Id1_label);
write_page.add(name1_label);
write_page.add(gender1_label);
write_page.add(birthDate1_label);
write_page.add(politicalOutlook1_label);
write_page.add(familyLocate1_label);
write_page.add(phone1_label);
write_page.add(dormitoryNum1_label);
write_page.add(ID1_field);
write_page.add(name1_field);
write_page.add(gender1_field);
write_page.add(birthDate1_field);
write_page.add(politicalOutlook1_field);
write_page.add(familyLocate1_field);
write_page.add(phone1_field);
write_page.add(dormitoryNum1_field);
write_page.add(return1_btn);
write_page.add(sure1_btn);
write_page.add(exit2_btn);
删除学生:
//删除学生信息按钮的监听器
delate_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//当按钮被单击时自动调动这个方法
public void actionPerformed(ActionEvent event)
{
JFrame delate_page = new JFrame("学生信息管理系统");
delate_page.setResizable(false);
delate_page.setSize(600, 600); //设置窗口的大小
delate_page.setLayout(null); //设置程序默认布局格式为空,以便于后期自己简单的设置布局
delate_page.setResizable(false); //设置不可缩放
//给主页设置位置
delate_page.setLocation(screenSizeWidth / 2 - windowWidth / 2 + 50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//给主页设置大小
delate_page.setSize(windowWidth, windowHeight);
//设置主页能够关闭,并且登录成功后将登录页面隐藏
delate_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
delate_page.setVisible(true);
setVisible(false);//登录页面隐藏
//声明
JLabel Menu2_label = new JLabel("删除学生信息");
JLabel Id2_label = new JLabel("请输入ID");
final JTextField ID2_field = new JTextField();
JButton return2_btn = new JButton("返回");
JButton sure2_btn = new JButton("确定");
JButton exit3_btn = new JButton("退出系统");
//设置各个标签和输入框的大小和位置
Menu2_label.setBounds(250, 75, 100, 100);
Id2_label.setBounds(180, 200, 200, 50);
ID2_field.setBounds(300, 210, 80, 25);
return2_btn.setBounds(120, 400, 100, 50);
sure2_btn.setBounds(250, 400, 100, 50);
exit3_btn.setBounds(380, 400, 100, 50);
//添加到面板
delate_page.add(Menu2_label);
delate_page.add(Id2_label);
delate_page.add(ID2_field);
delate_page.add(return2_btn);
delate_page.add(sure2_btn);
delate_page.add(exit3_btn);
修改学生信息:
/修改学生信息按钮的监听器
read_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//当按钮被单击时自动调动这个方法
public void actionPerformed(ActionEvent event)
{
JFrame read_page = new JFrame("学生信息管理系统");
read_page.setResizable(false);
read_page.setSize(600, 600); //设置窗口的大小
read_page.setLayout(null); //设置程序默认布局格式为空,以便于后期自己简单的设置布局
read_page.setResizable(false); //设置不可缩放
//给主页设置位置
read_page.setLocation(screenSizeWidth / 2 - windowWidth / 2 + 50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//给主页设置大小
read_page.setSize(windowWidth, windowHeight);
//设置主页能够关闭,并且登录成功后将登录页面隐藏
read_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
read_page.setVisible(true);
setVisible(false);//登录页面隐藏
//声明标签,按钮,
JLabel Menu3_label = new JLabel("修改学生信息");
JLabel xiugaiID_label = new JLabel("请输入要修改学生的ID:");
JLabel Id3_label = new JLabel("ID");
JLabel name3_label = new JLabel("name");
JLabel gender3_label = new JLabel("gender");
JLabel birthDate3_label = new JLabel("birthDate");
JLabel politicalOutlook3_label = new JLabel("politicalOutlook");
JLabel familyLocate3_label = new JLabel("familyLocate");
JLabel phone3_label = new JLabel("phone");
JLabel dormitoryNum3_label = new JLabel("dormitoryNum");
final JTextField ID3_field = new JTextField();
final JTextField xiugaiID_field = new JTextField();
final JTextField name3_field = new JTextField();
final JTextField gender3_field = new JTextField();
final JTextField birthDate3_field = new JTextField();
final JTextField politicalOutlook3_field = new JTextField();
final JTextField familyLocate3_field = new JTextField();
final JTextField phone3_field = new JTextField();
final JTextField dormitoryNum3_field = new JTextField();
JButton return3_btn = new JButton("返回");
JButton sure3_btn = new JButton("确定");
JButton exit4_btn = new JButton("退出系统");
//设置各个标签和输入框的大小和位置
Menu3_label.setBounds(250, 50, 100, 100);
xiugaiID_label.setBounds(200, 75, 100, 100);
Id3_label.setBounds(200, 150, 200, 50);
name3_label.setBounds(200, 190, 100, 50);
gender3_label.setBounds(200, 230, 100, 50);
birthDate3_label.setBounds(200, 270, 100, 50);
politicalOutlook3_label.setBounds(200, 310, 100, 50);
familyLocate3_label.setBounds(200, 350, 100, 50);
phone3_label.setBounds(200, 390, 100, 50);
dormitoryNum3_label.setBounds(200, 430, 100, 50);
xiugaiID_field.setBounds(300, 120, 80, 25);
ID3_field.setBounds(300, 160, 80, 25);
name3_field.setBounds(300, 200, 80, 25);
gender3_field.setBounds(300, 240, 80, 25);
birthDate3_field.setBounds(300, 280, 80, 25);
politicalOutlook3_field.setBounds(300, 320, 80, 25);
familyLocate3_field.setBounds(300, 360, 80, 25);
phone3_field.setBounds(300, 400, 80, 25);
dormitoryNum3_field.setBounds(300, 440, 80, 25);
return3_btn.setBounds(120, 500, 100, 50);
sure3_btn.setBounds(250, 500, 100, 50);
exit4_btn.setBounds(380, 500, 100, 50);
//添加到面板
read_page.add(xiugaiID_label);
read_page.add(xiugaiID_field);
read_page.add(Menu3_label);
read_page.add(Id3_label);
read_page.add(name3_label);
read_page.add(gender3_label);
read_page.add(birthDate3_label);
read_page.add(politicalOutlook3_label);
read_page.add(familyLocate3_label);
read_page.add(phone3_label);
read_page.add(dormitoryNum3_label);
read_page.add(ID3_field);
read_page.add(name3_field);
read_page.add(gender3_field);
read_page.add(birthDate3_field);
read_page.add(politicalOutlook3_field);
read_page.add(familyLocate3_field);
read_page.add(phone3_field);
read_page.add(dormitoryNum3_field);
read_page.add(return3_btn);
read_page.add(sure3_btn);
read_page.add(exit4_btn);
查看学生信息:
//查看学生信息按钮的监听器
display_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//当按钮被单击时自动调动这个方法
public void actionPerformed(ActionEvent event)
{
JFrame display_page = new JFrame("学生信息管理系统");
display_page.setResizable(false);
display_page.setSize(600, 600); //设置窗口的大小
display_page.setLayout(null); //设置程序默认布局格式为空,以便于后期自己简单的设置布局
display_page.setResizable(false); //设置不可缩放
//给主页设置位置
display_page.setLocation(screenSizeWidth / 2 - windowWidth / 2 + 50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//给主页设置大小
display_page.setSize(windowWidth, windowHeight);
//设置主页能够关闭,并且登录成功后将登录页面隐藏
display_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
display_page.setVisible(true);
setVisible(false);//登录页面隐藏
JLabel Menu4_label = new JLabel("查看学生信息");
JLabel Id4_label = new JLabel("请输入ID");
final JTextField ID4_field = new JTextField();
JButton return4_btn = new JButton("返回");
JButton sure4_btn = new JButton("确定");
JButton exit5_btn = new JButton("退出系统");
//设置各个标签和输入框的大小和位置
Menu4_label.setBounds(250, 75, 100, 100);
Id4_label.setBounds(180, 200, 200, 50);
ID4_field.setBounds(300, 210, 80, 25);
return4_btn.setBounds(120, 400, 100, 50);
sure4_btn.setBounds(250, 400, 100, 50);
exit5_btn.setBounds(380, 400, 100, 50);
//添加到面板
display_page.add(Menu4_label);
display_page.add(Id4_label);
display_page.add(ID4_field);
display_page.add(return4_btn);
display_page.add(sure4_btn);
display_page.add(exit5_btn);
退出系统:
//退出系统按钮的监听器
exit5_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//当按钮被单击时自动调动这个方法
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
构造函数:
switch(str){
case 1:
System.out.println("===========显示所有学生信息========");
sdm.diplayAllStudent();
break;
case 2:
System.out.println("===========写入学生信息========");
Students stu = new Students(sc.nextInt(),sc.next(),sc.next(),sc.next(),sc.next(),sc.next(),sc.nextInt(),sc.nextInt());
if(sdm.writeStudent(stu)){
System.out.println("添加成功");
}
break;
case 3:
System.out.println("===========删除学生信息========");
while(true){
String str2=sc.next();
boolean isNum = false;
for(int i=str2.length();--i>=0;){
int chr=str2.charAt(i);
if(chr<48 || chr>57)
isNum = true;
}
if(!isNum){
int id2 = Integer.parseInt(str2);
if(sdm.deleteStudent(id2)){
System.out.println("删除成功");
}
}
else{
if(str2.equals("exit"))
break;
else if(sdm.deleteStudent(str2)){
System.out.println("删除成功");
}
}
}
break;
case 4:
System.out.println("===========修改学生信息========");
break;
case 5:
System.out.println("===========查询学生信息========");
System.out.println("请输入姓名或学号");
while(true){
String str1=sc.nextLine();
Boolean bol = false;
for(int i=str1.length();--i>=0;){
int chr=str1.charAt(i);
if(chr<48 || chr>57)
bol = true;
}
if(bol){
int id1=Integer.parseInt(str1);
if(!sdm.readStudent(id1)){
System.out.println("查无此人");
}
}
if(!sdm.readStudent(str1)){
System.out.println("查无此人");
}
if(str1.equals("exit"))
break;
}
break;
case 6:
break;
}
}
}
public static boolean isNumeric(String str){//判断字符串是否为数字
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if(chr<48 || chr>57)
return false;
}
return true;
}
}
周次 | 总代码量 | 新增代码量 | 总文件数 | 新增文件数 |
---|---|---|---|---|
1 | 44 | 44 | 2 | 2 |
2 | 213 | 213 | 10 | 5 |
3 | 417 | 204 | 10 | 5 |
5 | 676 | 259 | 17 | 7 |
6 | 1071 | 405 | 24 | 7 |
7 | 1780 | 709 | 30 | 6 |
8 | 1900 | 120 | 35 | 5 |
9 | 2335 | 435 | 41 | 6 |
10 | 2767 | 432 | 48 | 7 |
11 | 3321 | 595 | 57 | 9 |
12 | 3601 | 280 | 63 | 6 |
13 | 4131 | 531 | 67 | 4 |
14 | 4537 | 406 | 73 | 6 |
15 | 4957 | 440 | 44 | 4 |
20 | 8102 | 2145 | 65 | 21 |
GIT地址:https://gitee.com/xinqingnian001/javalearn/commit/f0d4509eb55c6445b74346ba1b4f110706e266c7