1. 程式人生 > >java課程設計(學生信息管理系統)

java課程設計(學生信息管理系統)

gen 圖片 false 出生日期 resizable cnblogs orm size gin

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

java課程設計(學生信息管理系統)