学生学籍管理系统(含java源代码)

合集下载

(完整版)学生学籍管理系统(含java源代码)

(完整版)学生学籍管理系统(含java源代码)

学生学籍管理详细设计学号:____________姓名:____________班级:____________一、设计题目:学生学籍管理二:设计内容:设计GUI学生学籍管理界面,用户可以加入学生信息,并对基本信息进行修改,添加,查询,删除。

三:设计要求:进行简单的学生信息管理。

四:总体设计(1)登陆界面的设计(2)主窗体的设计(3)添加学生信息窗体(4)查询学生信息窗体(5)修改学生信息窗体(6)删除学生信息窗体(7)事件响应的处理五:具体设计(1)程序结构的说明:A.入口程序:student.java;B.登陆界面程序:mainframe.java;C.主窗体程序:interfac.java;D.添加信息窗口程序:tj.java;E.修改信息窗口程序:xg.java;F.查询信息窗口程序:cx.java;G.删除信息窗口程序:sc.java;H.程序数据连接:DatabaseConn.java;(2)程序代码及分析说明A.程序源代码(已提交)B.Student.java是程序的入口。

使登录窗口位于窗口中间,并且不可改变窗口大小。

C.mainframe.java是程序的登陆窗体。

输入用户名和密码(用户名和密码在数据库的password表中)点击“进入系统”,然后登陆界面消失;出现要操作的界面(屏幕左上角)。

D.tj.java是添加信息界面。

添加基本信息后,点击“添加信息”按钮,将信息加入xinxi表中。

E.xg.java是修改信息界面。

输入要修改的学号或姓名(两者数其一或全部输入),并输入所有信息,点击“修改信息”按钮(如果数据库中不存在此学号,则弹出对话框“无此学生信息”),若有则修改。

F.sc.java是删除信息界面。

输入要删除的学生的学号,点击“删除信息”按钮,弹出确认删除对话框,即可删除该生信息。

G.cx.java是查询信息界面。

输入要查询的学生学号,点击“信息查询”按钮,在相应的文本区里显示查询的信息。

学生信息管理系统JAVA源代码

学生信息管理系统JAVA源代码

学生信息管理系统JAVA源代码package stumanage;import javax.swing.*;import java.awt.*;import sun.awt.image.*;import java.awt.event.*;/*** <p>Title: </p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2003</p>* <p>Company: </p>* @author not attributable* @version 1.0*/public class WelcomeFrameextends JFrame {JPanel jPanel1 = new MyPanel();ImageIcon imageIcon1 = new ImageIcon("beautiful.jpg"); BorderLayout borderLayout1 = new BorderLayout();JPanel jPanel2 = new JPanel();GridBagLayout gridBagLayout1 = new GridBagLayout(); JButton jButton1 = new JButton();JButton jButton2 = new JButton();JButton jButton3 = new JButton();JButton jButton4 = new JButton();JButton jButton5 = new JButton();public WelcomeFrame() {try {jbInit();}catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) {WelcomeFrame welcomeFrame = new WelcomeFrame();welcomeFrame.pack();welcomeFrame.show();}private void jbInit() throws Exception {imageIcon1.setDescription("beautiful.jpg");imageIcon1.setImageObserver(this);jPanel1.setLayout(borderLayout1);jPanel1.setMinimumSize(new Dimension(600, 400));jPanel1.setPreferredSize(new Dimension(600, 420));this.setLocale(java.util.Locale.getDefault());this.setResizable(true);this.setSize(new Dimension(747, 396));this.setState(Frame.NORMAL);jPanel2.setBackground(UIManager.getColor("RadioButtonMenuItem.selectionBackgro und"));jPanel2.setForeground(Color.black);jPanel2.setMinimumSize(new Dimension(100, 30));jPanel2.setPreferredSize(new Dimension(100, 400));jPanel2.setLayout(gridBagLayout1);jButton1.setToolTipText(" 个人信息管理");jButton1.setText(" 个人信息管理");jButton1.addActionListener(new WelcomeFrame_jButton1_actionAdapter(this));jButton2.setToolTipText(" 选课信息管理");jButton2.setText(" 选课信息管理");jButton2.addActionListener(new WelcomeFrame_jButton2_actionAdapter(this));jButton3.setToolTipText("奖励信息管理");jButton3.setText("奖励信息管理");jButton3.addActionListener(new WelcomeFrame_jButton3_actionAdapter(this));jButton4.setToolTipText("职务信息管理");jButton4.setText("职务信息管理");jButton4.addActionListener(new WelcomeFrame_jButton4_actionAdapter(this));jButton5.setToolTipText("退出系统");jButton5.setText("退出系统");jButton5.addActionListener(new WelcomeFrame_jButton5_actionAdapter(this));this.getContentPane().add(jPanel1, BorderLayout.CENTER);jPanel1.add(jPanel2, BorderLayout.EAST);jPanel2.add(jButton1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));jPanel2.add(jButton2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 0, 0, 21), 0, 0));jPanel2.add(jButton3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 0, 10), 0, 0));jPanel2.add(jButton5, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 11), 21, 0));jPanel2.add(jButton4, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 0, 13, 0), 12, 0));}class MyPanelextends JPanel {public void paintComponent(Graphics g) {super.paintComponent(g);imageIcon1.paintIcon(this, g, 0, 0);}}void jButton4_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();MainFrame.jTabbedPane1.setSelectedComponent( MainFrame.jPanel4);}void jButton1_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();}void jButton3_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();MainFrame.jTabbedPane1.setSelectedComponent( MainFrame.jPanel3);}void jButton2_actionPerformed(ActionEvent e) {MainFrame.main( null );this.hide();MainFrame.jTabbedPane1.setSelectedComponent( MainFrame.jPanel2); }void jButton5_actionPerformed(ActionEvent e) {System.exit(0);}}class WelcomeFrame_jButton4_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton4_actionAdapter(WelcomeFrame adaptee) {this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton4_actionPerformed(e);}}class WelcomeFrame_jButton1_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton1_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton1_actionPerformed(e);}}class WelcomeFrame_jButton3_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton3_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton3_actionPerformed(e);}}class WelcomeFrame_jButton2_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton2_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton2_actionPerformed(e);}}class WelcomeFrame_jButton5_actionAdapter implementsjava.awt.event.ActionListener {WelcomeFrame adaptee;WelcomeFrame_jButton5_actionAdapter(WelcomeFrame adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.jButton5_actionPerformed(e);}}。

Java课程设计-学籍管理系统代码

Java课程设计-学籍管理系统代码

//Student_Management_System.java//JHelpTextPanel.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;//定义帮助文档类class JHelpTextPanel extends JPanel{Font newSmallTitleFont=new Font("楷体",Font.BOLD,12);JTextArea HelpText=new JTextArea();JHelpTextPanel(){setLayout(null);setBackground(Color.orange);HelpText.setBackground(Color.orange);HelpText.setForeground(Color.red);HelpText.setFont(newSmallTitleFont);HelpText.setBounds(0,0,600,600);add(HelpText);}}//Student_InforPanel .javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;class Student_InforPanel extends JPanel implements ActionListener {//四种常用字体的定义Font newTitleFont=new Font("楷体",Font.BOLD,40);Font newSmallTitleFont=new Font("楷体",Font.BOLD,25);Font newCommonFont=new Font("宋体",Font.BOLD,20);Font newSubMenuFont=new Font("宋体",Font.BOLD,15);Font NewSubMenuFont=new Font("宋体",Font.BOLD,10);//性别数组定义String os[]={" 男 "," 女 "};//定义确认对话框图标ImageIcon thinker=new ImageIcon("ICON//thinker.gif");//定义学生信息管理系统面板菜单控件JLabel StudentSno_Clue=new JLabel("学号:");JLabel StudentName_Clue=new JLabel("姓名:");JLabel StudentSex_Clue=new JLabel("性别:");JLabel StudentAge_Clue=new JLabel("年龄:");JLabel StudentClass_Clue=new JLabel("班级:");JLabel StudentDept_Clue=new JLabel("系别:");JTextField StudentSno_Input=new JTextField();JTextField StudentName_Input=new JTextField();ComboBoxModel Othermode=new OtherAModel();JComboBox StudentSex_Input=new JComboBox(Othermode);JTextField StudentAge_Input=new JTextField();JTextField StudentClass_Input=new JTextField();JTextField StudentDept_Input=new JTextField();JTextArea QueryInforShow=new JTextArea();JLabel QueryClue=new JLabel("以下是你要查询的学生信息:"); JButton Add_StudentInformation=new JButton("增加学生信息");JButton Del_StudentInformation=new JButton("删除学生信息");JButton Query_StudentInformation=new JButton("查询学生信息");JButton Modify_StudentInformation=new JButton("修改学生信息");//定义变量int ValidAge;String SnoOrigin;Student_InforPanel(){setBackground(Color.orange);QueryInforShow.setBackground(Color.orange);setLayout(null);StudentSno_Clue.setBounds(270,120,80,30);StudentSno_Clue.setFont(newCommonFont);StudentSno_Input.setBounds(350,120,120,30);StudentName_Clue.setBounds(270,170,80,30);StudentName_Clue.setFont(newCommonFont);StudentName_Input.setBounds(350,170,120,30);StudentSex_Clue.setBounds(270,220,80,30);StudentSex_Clue.setFont(newCommonFont);StudentSex_Input.setBounds(350,220,120,30);StudentAge_Clue.setBounds(270,270,80,30);StudentAge_Clue.setFont(newCommonFont);StudentAge_Input.setBounds(350,270,120,30); StudentClass_Clue.setBounds(270,320,80,30); StudentClass_Clue.setFont(newCommonFont);StudentClass_Input.setBounds(350,320,120,30); StudentDept_Clue.setBounds(270,370,80,30);StudentDept_Clue.setFont(newCommonFont);StudentDept_Input.setBounds(350,370,120,30);Query_StudentInformation.setBounds(80,120,130,30); Query_StudentInformation.setFont(newSubMenuFont);Query_StudentInformation.addActionListener(this); QueryClue.setBounds(80,180,300,50);QueryClue.setFont(newSubMenuFont);QueryInforShow.setBounds(80,220,530,100); QueryInforShow.setFont(newSubMenuFont);Del_StudentInformation.setBounds(80,120,130,30);Del_StudentInformation.setFont(newSubMenuFont);Del_StudentInformation.addActionListener(this);Add_StudentInformation.setBounds(80,170,130,30);Add_StudentInformation.setFont(newSubMenuFont);Add_StudentInformation.addActionListener(this);Modify_StudentInformation.setBounds(80,220,130,30); Modify_StudentInformation.setBounds(80,220,130,30); Modify_StudentInformation.setFont(newSubMenuFont); Modify_StudentInformation.addActionListener(this);add(StudentSno_Clue);add(StudentSno_Input);add(StudentName_Clue);add(StudentName_Input);add(StudentSex_Clue);add(StudentSex_Input);add(StudentAge_Clue);add(StudentAge_Input);add(StudentClass_Clue);add(StudentClass_Input);add(StudentDept_Clue);add(StudentDept_Input);add(QueryClue);add(QueryInforShow);add(Add_StudentInformation);add(Del_StudentInformation);add(Query_StudentInformation);add(Modify_StudentInformation);}public void actionPerformed(ActionEvent e){if(e.getSource()==Add_StudentInformation){if(IsValidAge(StudentAge_Input.getText())){String ***=(String)StudentSex_Input.getSelectedItem();MainMenu.myDatabase.Add_Database_Information(StudentSno_Input.ge tText(),StudentName_Input.getText(),***,ValidAge,StudentClass_Input.getT ext(),StudentDept_Input.getText());emptyInput();}}if(e.getSource()==Del_StudentInformation){QueryInforShow.setText("");if(MainMenu.myDatabase.Query_Database_Information(Studen tSno_Input.getText())){QueryInforShow.setText(DataBaseControl.temptInformation);int result=JOptionPane.showConfirmDialog(null,"你确定要删除该生信息吗?","ConfirmMessage",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,think er);if(result==JOptionPane.YES_OPTION){if(MainMenu.myDatabase.Del_Database_Information(St udentSno_Input.getText()))JOptionPane.showMessageDialog(null,"删除操作成功!","Happy Message",JOptionPane.PLAIN_MESSAGE);elseJOptionPane.showMessageDialog(null,"数据库操作出现异常,删除操作失败!","Error Message",JOptionPane.ERROR_MESSAGE);}}elseQueryInforShow.setText("对不起,没有找到你要删除的学生信息.");}if(e.getSource()==Query_StudentInformation){QueryInforShow.setText("");if(MainMenu.myDatabase.Query_Database_Information(Stud entSno_Input.getText()))QueryInforShow.setText(DataBaseControl.temptInformatio n);elseQueryInforShow.setText("对不起,没有你想要查询的学生信息");}if(e.getSource()==Modify_StudentInformation){if(IsValidAge(StudentAge_Input.getText()))MainMenu.myDatabase.Modify_Database_Information(SnoOri gin,StudentSno_Input.getText(),StudentName_Input.getText(),ValidAge,StudentClass_Inpu t.getText(),StudentDept_Input.getText());}}public boolean IsValidAge(String StringAge){try{ValidAge=Integer.parseInt(StringAge);}catch(NumberFormatException e){e.printStackTrace();return false;}if(ValidAge<=120&ValidAge>0)return true;else{JOptionPane.showMessageDialog(null,"你输入的年龄不合实际情况\n 请重新输入!","WARNING MESSAGE",JOptionPane.WARNING_MESSAGE);return false;}}class OtherAModel extends DefaultComboBoxModel{OtherAModel(){for(int i=0;i<os.length;i++)addElement(os[i]);}}public void emptyInput(){StudentSno_Input.setText("");StudentAge_Input.setText("");StudentName_Input.setText("");StudentClass_Input.setText("");StudentDept_Input.setText("");}public void OnlyShowSno(){StudentSno_Clue.setVisible(true);StudentSno_Input.setVisible(true);StudentSno_Input.setText("");QueryClue.setVisible(true);QueryInforShow.setVisible(true);StudentName_Clue.setVisible(false);StudentName_Input.setVisible(false);StudentSex_Clue.setVisible(false);StudentSex_Input.setVisible(false);StudentAge_Clue.setVisible(false);StudentAge_Input.setVisible(false);StudentClass_Clue.setVisible(false);StudentClass_Input.setVisible(false);StudentDept_Clue.setVisible(false);StudentDept_Input.setVisible(false);}//显示学生信息的所有面板控件public void ShowWhole(){StudentSno_Clue.setVisible(true);StudentSno_Input.setVisible(true);StudentSno_Input.setText("");QueryClue.setVisible(false);QueryInforShow.setVisible(false);StudentName_Clue.setVisible(true);StudentName_Input.setVisible(true);StudentName_Input.setText("");StudentSex_Clue.setVisible(true);StudentSex_Input.setVisible(true);StudentAge_Clue.setVisible(true);StudentAge_Input.setVisible(true);StudentAge_Input.setText("");StudentClass_Clue.setVisible(true);StudentClass_Input.setVisible(true);StudentClass_Input.setText("");StudentDept_Clue.setVisible(true);StudentDept_Input.setVisible(true);StudentDept_Input.setText("");}}//Student_ScorePanel.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;class Student_ScorePanel extends JPanel implements ActionListener {//三种常用字体的定义Font newTitleFont=new Font("楷体",Font.BOLD,40);Font newSmallTitleFont=new Font("楷体",Font.BOLD,25);Font newCommonFont=new Font("宋体",Font.BOLD,20);Font newSubMenuFont=new Font("宋体",Font.BOLD,15);Font NewSubMenuFont=new Font("宋体",Font.BOLD,10);//定义确认对话框图标ImageIcon thinker=new ImageIcon("ICON//thinker.gif");JLabel ScoreSno_Clue=new JLabel("学号:");JLabel ScoreEnglish_Clue=new JLabel("英语:");JLabel ScoreSeniorMath_Clue=new JLabel("高数:");JLabel ScoreC_Clue=new JLabel("C:");JLabel ScoreVC_Clue=new JLabel("VC:");JLabel ScoreJAVA_Clue=new JLabel("JAVA:");JTextField ScoreSno_Input=new JTextField();JTextField ScoreEnglish_Input=new JTextField();JTextField ScoreSeniorMath_Input=new JTextField();JTextField ScoreC_Input=new JTextField();JTextField ScoreVC_Input=new JTextField();JTextField ScoreJAVA_Input=new JTextField();JTextArea ScoreShow=new JTextArea();JLabel ScoreShowClue=new JLabel("你要查询的学生成绩信息为:");JButton Add_ScoreInformation=new JButton("增加学生成绩");JButton Del_ScoreInformation=new JButton("删除学生成绩");JButton Query_ScoreInformation=new JButton("查询学生成绩");JButton Modify_ScoreInformation=new JButton("修改学生成绩");//定义变量int ValidScore;String ScoreSno;Student_ScorePanel(){//学生成绩管理面板设置控件setBackground(Color.orange);ScoreShow.setBackground(Color.orange);setLayout(null);ScoreSno_Clue.setBounds(270,120,80,30);ScoreSno_Clue.setFont(newCommonFont);ScoreSno_Input.setBounds(350,120,120,30);ScoreEnglish_Clue.setBounds(270,170,80,30);ScoreEnglish_Clue.setFont(newCommonFont);ScoreEnglish_Input.setBounds(350,170,120,30);ScoreSeniorMath_Clue.setBounds(270,220,80,30); ScoreSeniorMath_Clue.setFont(newCommonFont); ScoreSeniorMath_Input.setBounds(350,220,120,30);ScoreC_Clue.setBounds(270,270,80,30);ScoreC_Clue.setFont(newCommonFont);ScoreC_Input.setBounds(350,270,120,30);ScoreVC_Clue.setBounds(270,320,80,30);ScoreVC_Clue.setFont(newCommonFont);ScoreVC_Input.setBounds(350,320,120,30);ScoreJAVA_Clue.setBounds(270,370,80,30);ScoreJAVA_Clue.setFont(newCommonFont);ScoreJAVA_Input.setBounds(350,370,120,30);Query_ScoreInformation.setBounds(80,120,130,30);Query_ScoreInformation.setFont(newSubMenuFont);Query_ScoreInformation.addActionListener(this); ScoreShowClue.setFont(newSubMenuFont);ScoreShowClue.setBounds(80,180,300,50);ScoreShow.setFont(newSubMenuFont);ScoreShow.setBounds(80,220,530,100);Del_ScoreInformation.setBounds(80,120,130,30);Del_ScoreInformation.setFont(newSubMenuFont);Del_ScoreInformation.addActionListener(this);Add_ScoreInformation.setBounds(80,170,130,30);Add_ScoreInformation.setFont(newSubMenuFont);Add_ScoreInformation.addActionListener(this);Modify_ScoreInformation.setBounds(80,220,130,30);Modify_ScoreInformation.setFont(newSubMenuFont);Modify_ScoreInformation.addActionListener(this);add(ScoreSno_Clue);add(ScoreSno_Input);add(ScoreEnglish_Clue);add(ScoreEnglish_Input);add(ScoreSeniorMath_Clue);add(ScoreC_Clue);add(ScoreSeniorMath_Input);add(ScoreC_Input);add(ScoreVC_Clue);add(ScoreVC_Input);add(ScoreJAVA_Clue);add(ScoreJAVA_Input);add(ScoreShow);add(ScoreShowClue);add(Add_ScoreInformation);add(Del_ScoreInformation);add(Query_ScoreInformation);add(Modify_ScoreInformation);}public void actionPerformed(ActionEvent e){if(e.getSource()==Query_ScoreInformation)//查询按纽事件触发处理{if(MainMenu.myDatabase.QueryScoreFunction(ScoreSno_Input.getText ())){ScoreShow.setText("");ScoreShow.append("学号\t\t英语\t高数\tC\tVC\tJAVA\n");ScoreShow.append(MainMenu.myDatabase.Student_Score[MainMenu.my Database.NowScoreNum]);}else{ScoreShow.setText("");ScoreShow.setText("对不起,没有你想要查找的学生信息!");}}if(e.getSource()==Add_ScoreInformation)//增加学生成绩信息按纽的时间触发{if(IsValidScore(ScoreEnglish_Input.getText())&&IsValidScore(Scor eSeniorMath_Input.getText())&&IsValidScore(ScoreC_Input.getText())&&IsValidScore(ScoreVC_Input.getText()) &&IsValidScore(ScoreJAVA_Input.getText())){IsValidScore(ScoreEnglish_Input.getText());int englishscore=ValidScore;IsValidScore(ScoreSeniorMath_Input.getText());int seniorscore=ValidScore;IsValidScore(ScoreC_Input.getText());int cscore=ValidScore;IsValidScore(ScoreVC_Input.getText());int vcscore=ValidScore;IsValidScore(ScoreJAVA_Input.getText());int javascore=ValidScore;MainMenu.myDatabase.addStudentScoreInformation(ScoreSno_Inpu t.getText(),englishscore,seniorscore, cscore, vcscore, javascore);emptyInput();}}if(e.getSource()==Del_ScoreInformation)//删除学生成绩信息事件触发处理{if(MainMenu.myDatabase.QueryScoreFunction(ScoreSno_Input.getText ())){ScoreShow.setText("");ScoreShow.append("学号\t\t英语\t高数\tC\tVC\tJAVA\n");ScoreShow.append(MainMenu.myDatabase.Student_Score[MainMenu.my Database.NowScoreNum]);int result=JOptionPane.showConfirmDialog(null,"你真的要删除该学生的成绩信息吗?","Confirm Message",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,thinker);if(result==JOptionPane.YES_OPTION)MainMenu.myDatabase.DelScoreFunction(ScoreSno_Input.getText( ));}else{ScoreShow.setText("");ScoreShow.setText("对不起,你要删除的学生成绩信息不存在!");}}if(e.getSource()==Modify_ScoreInformation)//修改数据库中学生成绩信息事件的触发{if(IsValidScore(ScoreEnglish_Input.getText())&&IsValidScore(Scor eSeniorMath_Input.getText())&&IsValidScore(ScoreC_Input.getText())&&IsValidScore(ScoreVC_Input.getT ext())&&IsValidScore(ScoreJAVA_Input.getText())){IsValidScore(ScoreEnglish_Input.getText());int englishscore=ValidScore;IsValidScore(ScoreSeniorMath_Input.getText());int seniorscore=ValidScore;IsValidScore(ScoreC_Input.getText());int cscore=ValidScore;IsValidScore(ScoreVC_Input.getText());int vcscore=ValidScore;IsValidScore(ScoreJAVA_Input.getText());int javascore=ValidScore;MainMenu.myDatabase.ModifyStudentScoreInformation(Scor eSno_Input.getText(),ScoreSno,englishscore,seniorscore, cscore, vcscore, javascore);emptyInput();}}}public boolean IsValidScore(String stringAge)//判断成绩输入是否合法{try{ValidScore=Integer.parseInt(stringAge);}catch(NumberFormatException e){JOptionPane.showMessageDialog(null,"成绩输入中含有非法字符!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return false;}if(ValidScore>100||ValidScore<0){JOptionPane.showMessageDialog(null,"分数只能在0~100之间的整数!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return false;}return true;}//只显示学生成绩面板中学号相关控件public void ScoreShowOnlySno(){ScoreSno_Clue.setVisible(true);ScoreSno_Input.setVisible(true);ScoreSno_Input.setText("");ScoreShowClue.setVisible(true);ScoreShow.setVisible(true);ScoreEnglish_Clue.setVisible(false);ScoreEnglish_Input.setVisible(false);ScoreEnglish_Input.setText("");ScoreSeniorMath_Clue.setVisible(false);ScoreSeniorMath_Input.setVisible(false);ScoreSeniorMath_Input.setText("");ScoreC_Clue.setVisible(false);ScoreC_Input.setVisible(false);ScoreC_Input.setText("");ScoreVC_Clue.setVisible(false);ScoreVC_Input.setVisible(false);ScoreVC_Input.setText("");ScoreJAVA_Clue.setVisible(false);ScoreJAVA_Input.setVisible(false);ScoreJAVA_Input.setText("");}public void emptyInput()//清空成绩输入控件{ScoreSno_Input.setText("");ScoreEnglish_Input.setText("");ScoreSeniorMath_Input.setText("");ScoreC_Input.setText("");ScoreVC_Input.setText("");ScoreJAVA_Input.setText("");}//显示学生成绩面板中所有控件public void ScoreShowWhole(){ScoreSno_Clue.setVisible(true);ScoreSno_Input.setVisible(true);ScoreShowClue.setVisible(false);ScoreShow.setVisible(false);ScoreEnglish_Clue.setVisible(true);ScoreEnglish_Input.setVisible(true);ScoreSeniorMath_Clue.setVisible(true);ScoreSeniorMath_Input.setVisible(true);ScoreC_Clue.setVisible(true);ScoreC_Input.setVisible(true);ScoreVC_Clue.setVisible(true);ScoreVC_Input.setVisible(true);ScoreJAVA_Clue.setVisible(true);ScoreJAVA_Input.setVisible(true);}}//DataBaseControl.javaimport java.awt.*;import javax.swing.*;import java.io.*;import java.sql.*;import java.awt.event.*;import java.util.*;//数据库操作class DataBaseControl{//private String s="";//登录用户信息String UserRealName;String UserSex;int UserAge;String UserClass;String UserDept;//类中公有变量类型变量String LoginName="";String PW="";int Rank;final int MaxNum=20;String Student_Information[]=new String[MaxNum];String Student_Score[]=new String[MaxNum];String[] Database_Score={"学号","英语","高数","C","VC","JAVA"}; String[] Database_Information={"学号","姓名","性别","年龄","班级","系别"};int NowScoreNum;int NowInformationNum;static String temptInformation="";private Connection con1;private Statement st1;String str;public void init(String UserName,String PassWord,int i){LoginName=UserName;PW=PassWord;Rank=i;}public boolean ConnectDataBase()//连接数据源{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("Driver not found!");return false;}try{con1=DriverManager.getConnection("jdbc:odbc:学生管理数据库");st1=con1.createStatement();}catch(SQLException e){System.out.println("Data Source not found!");return false;}return true;}public int QueryUserLogin()//用户身份验证{int i=0;if(ConnectDataBase()){try{ResultSet rs1=st1.executeQuery("select* from UserLogin where 用户名='"+LoginName+"'");while(rs1.next()){if((rs1.getString(3).equals(PW))&&(rs1.getInt(4) ==Rank)){JOptionPane.showMessageDialog(null,"登录成功!\n"+rs1.getString(2)+"欢迎你使用学生管理系统","Happy Message",JOptionPane.PLAIN_MESSAGE);if(Rank==1)return 1;elsereturn 2;}//end-ifi++;}//end-whileif(i==0){JOptionPane.showMessageDialog(null,"该用户不存在!","Error Message",JOptionPane.ERROR_MESSAGE);}else{JOptionPane.showMessageDialog(null,"你的密码或者用户登级有误!","Error Message",JOptionPane.ERROR_MESSAGE);}Close_database();}catch(SQLException e1){System.out.println(e1.toString());return 0;}}//end-ifreturn 0;}public void ChangeUserPW(String newPW)//修改用户密码{if(ConnectDataBase()){try{st1.executeUpdate("UPDATE UserLogin SET 用户密码='"+newPW+"' where 用户名='"+LoginName+"'");Close_database();}catch(SQLException e){System.out.println(e.toString());JOptionPane.showMessageDialog(null,"对数据库操作发生错误!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return;}JOptionPane.showMessageDialog(null,"修改密码成功!\n请记住你的新密码.","SucessfulMessage",JOptionPane.PLAIN_MESSAGE);}}public void ShowUserInformation()//显示用户信息{if(ConnectDataBase()){try{ResultSet sr=st1.executeQuery("select* from UserBasicInformation where 用户名='"+LoginName+"'");while(sr.next()){UserRealName=sr.getString(2);UserSex=sr.getString(3);UserAge=sr.getInt(4);UserClass=sr.getString(5);UserDept=sr.getString(6);}Close_database();}catch(SQLException e){System.out.println("Error!!");}}//end-if}public void DeleteUser()//注销帐户{String str1;if(ConnectDataBase()){try{str1="DELETE FROM UserLogin where 用户名='"+LoginName+"'";str="DELETE FROM UserBasicInformation where 用户名='"+LoginName+"'";st1.executeUpdate(str1);st1.executeUpdate(str);Close_database();//关闭数据库连接}catch(SQLException e){System.out.println("Error!!");}}JOptionPane.showMessageDialog(null,"注销帐户成功!","HappyMessage",JOptionPane.PLAIN_MESSAGE);}///////////////////////////////////////学生信息处理函数//////////////////////////////////////////////////////public void show_DataBase_Information()//显示数据库中学生的个人基本信息{String Information;if(ConnectDataBase()){try{str="SELECT* FROM Student_Basic_Information";ResultSet s1=st1.executeQuery(str);int i=0;while(s1.next()){if(i>MaxNum)break;Information=s1.getString(1)+"\t"+s1.getString(2)+"\t"+s1.g etString(3)+"\t"+s1.getLong(4)+"\t"+s1.getString(5)+"\t"+s1.getString(6)+"\n";Student_Information[i]=Information;i++;}NowInformationNum=i;Close_database();}catch(SQLException e){System.out.println(e.toString());}}}public boolean Query_Database_Information(String sno)//显示查询数据库中学生信息{if(ConnectDataBase()){try{str="select* from Student_Basic_Information where 学号='"+sno+"'";ResultSet s1=st1.executeQuery(str);int i=0;while(s1.next()){temptInformation=s1.getString(1)+"\t"+s1.getString(2)+"\t" +s1.getString(3)+"\t"+s1.getLong(4)+"\t"+s1.getString(5)+"\t"+s1.getString(6)+"\n";i++;}Close_database();if(i>0)return true;}catch(SQLException e){e.printStackTrace();return false;}}return false;}public void Add_Database_Information(String sno,String name,String ***,int age,String classname,String dept){//向数据库中加入新生的基本信息if(ConnectDataBase()){try{str="INSERT INTOStudent_Basic_Information"+"(学号,姓名,性别,年龄,班级,系别)";str=str+"VALUES('"+sno+"','"+name+"',' "+***+"',"+age+",'"+classname+"','"+dept+"')";st1.executeUpdate(str);Close_database();}catch(SQLException e){e.printStackTrace();return;}JOptionPane.showMessageDialog(null,"加入新生记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}public boolean Del_Database_Information(String sno)//删除数据库中某个学生的基本信息{if(ConnectDataBase()){try{str="DELETE FROM Student_Basic_Information WHERE 学号='"+sno+"'";st1.executeUpdate(str);Close_database();}catch(SQLException e){e.printStackTrace();return false;}return true;}return false;}public void Modify_Database_Information(String sno,Stringsno1,String name,int age,String classname,String dept){//修改数据库中学生基本信息if(ConnectDataBase()){try{str="update Student_Basic_Information set 学号='"+sno1+"' where 学号='"+sno+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 姓名='"+name+"' where 学号='"+sno1+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 年龄="+age+" where 学号='"+sno1+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 班级='"+classname+"' where 学号='"+sno1+"'";st1.executeUpdate(str);str="update Student_Basic_Information set 系别='"+dept+"' where 学号='"+sno1+"'";st1.executeUpdate(str);Close_database();}catch(SQLException e){e.printStackTrace();return;}JOptionPane.showMessageDialog(null,"修改学生信息记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}////////////////////////////////////////学生成绩函数///////////////////////////////////////////////public void show_DataBase_Score()//显示数据库中学生的成绩信息{String score;if(ConnectDataBase()){try{int i=0;str="SELECT* FROM StudentScore";ResultSet s2=st1.executeQuery(str);while(s2.next()){if(i>MaxNum)break;score=s2.getString(1)+"\t"+s2.getLong(2)+"\t"+s2.g etLong(3)+"\t"+s2.getLong(4)+"\t"+s2.getLong(5)+"\t"+s2.getLong(6)+"\n";Student_Score[i]=score;i++;}NowScoreNum=i;Close_database();}catch(SQLException e){System.out.println(e.toString());}}}public boolean QueryScoreFunction(String SnoN){//根据学号查询学生的成绩信息String score;boolean find=false;if(ConnectDataBase()){try{str="SELECT* FROM StudentScore WHERE 学号='"+SnoN+"'";ResultSet s2=st1.executeQuery(str);while(s2.next()){find=true;score=s2.getString(1)+"\t"+s2.getLong(2)+"\t"+s2.getLong (3)+"\t"+s2.getLong(4)+"\t"+s2.getLong(5)+"\t"+s2.getLong(6);Student_Score[NowScoreNum]=score;}Close_database();}catch(SQLException e){e.printStackTrace();}}if(find)return true;elsereturn false;}public void addStudentScoreInformation(String sno,int englishscore,int seniorscore,int cscore,int vcscore,int javascore){//加入学生的成绩信息if(ConnectDataBase()){try{str="INSERT INTO StudentScore"+"(学号,英语,高数,C,VC,JAVA)";str=str+"VALUES('"+sno+"',"+englishscore+","+seniorscore+","+cscore+","+vcscore+","+javascore+")";st1.executeUpdate(str);Close_database();}catch(SQLException e){JOptionPane.showMessageDialog(null,"数据库操作发生异常\n加入学生成绩记录操作失败!","ERROR MESSAGE",JOptionPane.ERROR_MESSAGE);return;}JOptionPane.showMessageDialog(null,"加入新生记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}public void DelScoreFunction(String sno){//删除学生的成绩信息if(ConnectDataBase()){try{str="DELETE FROM StudentScore WHERE 学号='"+sno+"'";st1.executeUpdate(str);}catch(SQLException e){JOptionPane.showMessageDialog(null,"数据库操作发生异常\n删除学生成绩记录操作失败!","ERROR MESSAGE",JOptionPane.PLAIN_MESSAGE);return;}JOptionPane.showMessageDialog(null,"删除学生成绩记录操作成功!","HAPPY MESSAGE",JOptionPane.PLAIN_MESSAGE);}}public void ModifyStudentScoreInformation(String sno1,String sno,int englishscore,int seniorscore,int cscore,int vcscore,int javascore)//修改数据库中学生成绩信息{if(ConnectDataBase()){try{str="update StudentScore set 学号='"+sno1+"' where 学号='"+sno+"'";st1.executeUpdate(str);str="update StudentScore set 英语="+englishscore+" where 学号。

javaweb学生管理系统源代码介绍

javaweb学生管理系统源代码介绍

javaweb学生管理系统源代码介绍简介本文档将介绍一个基于JavaWeb的学生管理系统的源代码。

该系统通过使用Java语言编写,结合了Web开发技术,实现了学生信息的录入、查询、修改和删除等功能。

该系统具有良好的用户界面和功能模块,可以方便地进行学生信息管理。

系统结构该学生管理系统主要由以下几个主要模块组成:1.用户登录模块:该模块实现了用户的登录功能,将验证用户输入的用户名和密码与数据库中已注册用户的信息进行匹配,以确定用户是否能够成功登录系统。

2.学生信息录入模块:该模块提供了一个用户界面,用户可以在界面上输入学生的基本信息,如学号、姓名、性别、年龄等,并将这些信息存储到数据库中。

3.学生信息查询模块:该模块允许用户根据学号或姓名等信息进行学生信息的查询,系统将根据用户输入的条件在数据库中查询相应的学生信息,并将查询结果返回给用户。

4.学生信息修改模块:该模块允许用户修改已录入的学生信息,在界面上展示当前学生的信息,并允许用户进行修改操作,修改后的信息将被保存到数据库中。

5.学生信息删除模块:该模块允许用户删除已录入的学生信息,用户可以根据学号或姓名等条件选择要删除的学生信息,被删除的学生信息将从数据库中移除。

技术细节该学生管理系统的源代码主要使用了以下技术进行开发:1.Java语言:系统的后端主要由Java编写,通过使用Java的面向对象特性和类库函数,实现了系统的各种功能模块。

2.Servlet:Servlet是JavaWeb开发中的一种组件技术,用于处理HTTP请求和响应。

系统中的各个功能模块都通过Servlet进行处理,提供了合适的响应和数据处理操作。

3.JSP:JSP是JavaServer Pages的缩写,是一种在HTML页面中嵌入Java代码的技术。

在本系统中,JSP主要用于生成用户界面,通过嵌入Java代码和引用系统的Java类,实现了用户界面与后端业务逻辑的交互。

4.JDBC:JDBC是Java数据库连接的简称,用于与数据库进行交互。

java学生信息管理系统源代码

java学生信息管理系统源代码

java学⽣信息管理系统源代码本⽂实例为⼤家分享了java学⽣信息管理系统的具体代码,实现学⽣信息:增加 int[] a=new int[9] 、删除、查找、更改,供⼤家参考,具体内容如下/*学⽣信息管理系统,实现学⽣信息:*增加 int[] a=new int[9]*删除*查找*更改*/import java.util.Scanner;//导⼊java输⼊流import ng.*;import java.io.*;class Student{private static Student[] s=new Student[2];int n=0;private String name;private int num;private String classAge;public void judge()throws IOException{int i;char ch;String str;Scanner In=new Scanner(System.in);if(n==0){System.out.print("你还没有录⼊任何学⽣,是否录⼊(Y/N):");str=In.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输⼊有误,请重新输⼊:");str=In.next();ch=str.charAt(0);}if(ch=='Y'||ch=='y'){this.add();}if(ch=='N'||ch=='n'){this.menu();}}}public void menu()throws IOException//定义菜单函数{int a;//定义switch语句变量Scanner in=new Scanner(System.in);//实例化输⼊流对象System.out.println("*********学⽣信息管理系统功能表*********");System.out.println("***** 1.增加 *****");System.out.println("***** 2.显⽰ *****");System.out.println("***** 3.修改 *****");System.out.println("***** 4.删除 *****");System.out.println("***** 5.查看 *****");System.out.println("***** 0.退出 *****");System.out.println("****************************************");System.out.print("请选择(0~5):");a=in.nextInt();while(a<0||a>5){System.out.print("输⼊超出范围,请重新输⼊:");a=in.nextInt();}switch(a){case 1:this.add();break;case 4:this.delete();break;case 5:this.look();break;case 0:System.exit(0);break;}}public void add()throws IOException//定义增加函数{String str,str1,str2;int i,num1,t=1;char ch,ch1;FileWriter fw=new FileWriter("F://javaFile//student.txt",true); fw.write(" 录⼊的学⽣信息列表\r\n\r\n学号姓名班级\r\n"); Scanner In=new Scanner(System.in);while(t==1){System.out.print("请输⼊学⽣学号:");num1=In.nextInt();for(i=0;i<n;i++){while(s[i].num==num1){System.out.println("已存在此学号,请重新输⼊");System.out.print("请输⼊学号:");num1=In.nextInt();}}s[n].num=num1;str2=String.valueOf(num1);fw.write(str2+" ");System.out.println();System.out.print("请输⼊学⽣姓名:");s[n].name=In.next();fw.write(s[n].name+" ");System.out.println();System.out.print("请输⼊学⽣班级:");s[n].classAge=In.next();fw.write(s[n].classAge+"\r\n");++n;fw.close();System.out.println();System.out.print("是否继续添加(Y/N)");str=In.next();ch=str.charAt(0);while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y'){System.out.print("输⼊有误,请重新输⼊:");str=In.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){break;}}System.out.println();System.out.print("是否返回主菜单(Y/N)");str1=In.next();ch1=str1.charAt(0);while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n'){System.out.print("输⼊有误,请重新输⼊:");str1=In.next();ch1=str1.charAt(0);}if(ch1=='Y'||ch1=='y'){this.menu();}if(ch1=='N'||ch1=='n'){System.out.println("正在退出...谢谢使⽤!");System.exit(0);}}public void show()throws IOException{int i;this.judge();System.out.println("本次操作共录⼊"+n+"位学⽣!");System.out.println("你录⼊的学⽣信息如下:");System.out.println();System.out.println("学号\t\t姓名\t班级");for(i=0;i<n;i++){System.out.println(s[i].num+" "+s[i].name+" "+s[i].classAge);}System.out.println("系统返回主菜单!");this.menu();}public void delete()throws IOException//删除信息功能实现注:本功能暂时不具备可扩展性 {this.judge();int j=0,t=0,k=0,num1;char ch;String str;Scanner pin=new Scanner(System.in);System.out.print("请输⼊要删除的学号:");num1=pin.nextInt();for(j=0;j<n;j++){if(s[j].num==num1){k=1;t=j;}}if(k==0){System.out.println("对不起!你要删除的学号不存在!");System.out.println("系统将返回主菜单!");this.menu();}if(k==1){System.out.println("你要删除的学⽣信息如下:");//打印管理员要删除的学⽣信息System.out.println("学号\t姓名\t班级");//本功能暂时不备扩展性System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge);System.out.println();System.out.print("你确定要删除(Y/N):");str=pin.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输⼊有误,请重新输⼊:");str=pin.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){System.out.println();System.out.println("系统返回主菜单!");this.menu();}if(ch=='Y'||ch=='y'){for(j=t;j<n-1;j++){s[j]=s[j+1];}n--;System.out.println("数据成功删除!");System.out.println("系统返回主菜单!");this.menu();}}}public void look()throws IOExceptionFileReader fr=new FileReader("F://javaFile//student.txt");int a;while((a=fr.read())!=-1){System.out.print((char)a);}fr.close();System.out.println("系统返回主菜单!");System.out.println();this.menu();}public void modif()throws IOException{this.judge();int j=0,t=0,k=0,num2,num3,moi,c=1;char ch;String str,str1,str2;Scanner pin=new Scanner(System.in);System.out.print("请输⼊要修改的学号:");num2=pin.nextInt();for(j=0;j<n;j++){if(s[j].num==num2){k=1;t=j;}}if(k==0){System.out.println("对不起!你要修改的学号不存在!");System.out.println("系统将返回主菜单!");this.menu();}if(k==1){System.out.println("你要修改的学⽣信息如下:");//打印管理员要删除的学⽣信息System.out.println("学号\t姓名\t班级");//本功能暂时不备扩展性System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge);System.out.println();System.out.print("你确定要修改(Y/N):");str=pin.next();ch=str.charAt(0);while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输⼊有误,请重新输⼊:");str=pin.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){System.out.println();System.out.println("系统返回主菜单!");this.menu();}while(c==1){if(ch=='Y'||ch=='y'){System.out.println("****************************************");System.out.println("***** 1.修改学号 *****");System.out.println("***** 2.修改班级 *****");System.out.println("***** 3.修改姓名 *****");System.out.println("****************************************");System.out.print("请选择:");moi=pin.nextInt();switch(moi){case 1:System.out.print("请输⼊新的学号:");num3=pin.nextInt();s[t].num=num3;break; case 2:System.out.print("请输⼊新的班级:");str1=pin.next();s[t].classAge=str1;break; case 3:System.out.print("请输⼊新的姓名:");str2=pin.next();s[t].name=str2;break;}System.out.println("数据已成功修改!");}str=pin.next();ch=str.charAt(0);System.out.println();while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'){System.out.print("输⼊有误,请重新输⼊:");str=pin.next();ch=str.charAt(0);}if(ch=='N'||ch=='n'){break;}}}System.out.println();System.out.println("系统返回主菜单!");this.menu();}public static void main(String[] args)throws IOException{Student stu=new Student();for(int i=0;i<2;i++){s[i]=new Student();}stu.menu();}}更多学习资料请关注专题《》。

(完整版)JAVA学生管理系统源代码

(完整版)JAVA学生管理系统源代码

JA V A学生管理系统源代码一、程序import java.util.*;public class Test {//主程序public static void main(String[] args){Scanner in = new Scanner(System.in);System.out.println("------请定义学生的人数:------");Student[] stuArr = new Student[in.nextInt()];Admin adminStu = new Admin();while(true){System.out.println("-----请选择你要执行的功能-----");System.out.println("10:添加一个学生");System.out.println("11:查找一个学生");System.out.println("12:根据学生编号更新学生基本信息");System.out.println("13:根据学生编号删除学生");System.out.println("14:根据编号输入学生各门成绩");System.out.println("15:根据某门成绩进行排序");System.out.println("16:根据总分进行排序");System.out.println("99:退出系统");String number = in.next();if(number.equals("10")){System.out.println("请输入学生的编号:");int num = in.nextInt();System.out.println("请输入学生的姓名:");String name = in.next();System.out.println("请输入学生的年龄:");int age = in.nextInt();adminStu.Create(num,name,age,stuArr);//添加学生}else if(number.equals("11")){System.out.println("执行查找学生基本信息的操作");System.out.println("请输入学生的编号进行查找:");int num = in.nextInt();adminStu.find(num,stuArr);//查找学生}else if(number.equals("12")){System.out.println("执行更新学员的基本信息操作");System.out.println("请输入学生的编号:");int num = in.nextInt();System.out.println("请输入学生的姓名:");String name = in.next();System.out.println("请输入学生的年龄:");int age = in.nextInt();adminStu.update(num,name,age,stuArr);//更新学生基本信息}else if(number.equals("13")){System.out.println("执行删除学生操作");System.out.println("请输入学生编号:");int num = in.nextInt();adminStu.delete(num,stuArr);//删除学生}else if(number.equals("14")){System.out.println("执行输入成绩操作");System.out.println("请输入学生编号:");int num = in.nextInt();adminStu.input(num, stuArr);//输入成绩}else if(number.equals("15")){System.out.println("执行根据某科目成绩排序操作");System.out.println("请选择需要排序的科目名(1.java 2.C# 3.html 4.sql):");int num = in.nextInt();adminStu.courseSort(num,stuArr);//按科目排序}else if(number.equals("16")){System.out.println("执行根据总分排序操作");adminStu.sumSort(stuArr);//按总分排序}else if(number.equals("99")){System.out.println("--------程序已退出--------");//break;System.exit(0);}}}}二、学生类public class Student {//学生类private int num;private String name;private int age;private int java;private int C;private int html;private int sql;private int sum;private int avg;public int getNum() {return num;}public void setNum(int num) { this.num = num;}public String getName() {return name;}public void setName(String name) { = name;}public int getAge() {return age;}public void setAge(int age) { this.age = age;}public int getJava() {return java;}public void setJava(int java) { this.java = java;}public int getC() {return C;}public void setC(int c) {C = c;}public int getHtml() {return html;}public void setHtml(int html) { this.html = html;}public int getSql() {return sql;}public void setSql(int sql) { this.sql = sql;}public int getSum() {return sum;}public void setSum() {this.sum = this.java+this.C+this.html+this.sql;}public int getAvg() {return avg;}public void setAvg() {this.avg = this.sum/4;}public String toString(){String str= "\t"+this.num+"\t"++"\t"+this.age+"\t"+this.java+"\t"+this.C+"\t"+this.html+"\t"+this.sql+"\t"+this.sum+"\t"+this.avg;return str;}}三、管理学生类import java.util.*;public class Admin {//用来管理学生的一个类String msg = "\t编号\t姓名\t年龄\tjava\tC#\thtml\tsql\t总分\t 平均分";public void print(Student[] arr){//刷新数据的方法System.out.println(msg);for(int i=0;i<arr.length;i++){if(arr[i]!=null){arr[i].setSum();arr[i].setAvg();System.out.println(arr[i]);}}}public boolean exist(int num,Student stu){//判断学生是否存在的方法if(stu!=null){if(stu.getNum()==num){return true;}else{return false;}}return false;}public void Create(int num,String name,int age,Student[] arr){//添加学生的方法Student stu = new Student();stu.setNum(num);stu.setName(name);stu.setAge(age);int i = this.setIndex(arr);if(i==99999){System.out.println("学生人数已添满,不能再添加了");}else{arr[i]=stu;}this.print(arr);}public int setIndex(Student[] arr){//返回数组为空的下标for(int i=0;i<arr.length;i++){if(arr[i]==null){return i;}}return 99999;}public void find(int num,Student[] arr){//查询学生的方法for(int i=0;i<arr.length;i++){//判断学生是否存在if(this.exist(num,arr[i])==true){System.out.println(msg);System.out.println(arr[i]);return;}}System.out.println("-----没有这个学生的存在-----");}public void update(int num,String name,int age,Student[] arr){//更新学生基本信息的方法for(int i=0;i<arr.length;i++){if(this.exist(num, arr[i])==true){arr[i].setName(name);arr[i].setAge(age);System.out.println("--------更新学生信息成功!-------");this.print(arr);return;}}System.out.println("------没找到这个学生更新信息失败------");}public void delete(int num,Student[] arr){//删除学生的方法for(int i=0;i<arr.length;i++){if(this.exist(num,arr[i])){arr[i] = null;this.print(arr);return;}}System.out.println("您所指定编号的学生不存在");}public void input(int num,Student[] arr){//输入学生成绩的方法for(int i=0;i<arr.length;i++){if(this.exist(num, arr[i])){Scanner in = new Scanner(System.in);System.out.println("请输入"+arr[i].getName()+"java 的成绩:");if(in.hasNextInt()){//输入非整形数则不执行arr[i].setJava(in.nextInt());}else{return;}System.out.println("请输入"+arr[i].getName()+"C#的成绩:");if(in.hasNextInt()){arr[i].setC(in.nextInt());}else{return;}System.out.println("请输入"+arr[i].getName()+"html 的成绩:");if(in.hasNextInt()){arr[i].setHtml(in.nextInt());}else{return;}System.out.println("请输入"+arr[i].getName()+"sql 的成绩:");if(in.hasNextInt()){arr[i].setSql(in.nextInt());}else{return;}this.print(arr);return;}}}public void courseSort(int num,Student[] arr){//根据指定科目排序的方法if(num==1){//这里不能用冒泡排序(因为冒泡排序是相邻的比较,而相邻的可能不存在,那么相隔的两个就不能交换)for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getJava()<arr[j].getJava()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}else if(num==2){for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getC()<arr[j].getC()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}else if(num==3){for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getHtml()<arr[j].getHtml()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}else if(num==4){for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getSql()<arr[j].getSql()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}}this.print(arr);}public void sumSort(Student[] arr){//根据总分排序的方法for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[i]!=null&&arr[j]!=null){if(arr[i].getSum()<arr[j].getSum()){Student t = arr[i];arr[i] = arr[j];arr[j] = t;}}}}this.print(arr);}}。

学生信息管理系统java课程设计(含源代码)

JAVA 程序设计 课程设计陈述宇文皓月课 题: 学生信息管理系统 姓 名: 学 号: 同组姓名: 专业班级: 指导教师: 设计时间:目 录1、需要实现的功能32、设计目的3 1、功能模块划分32、数据库结构描述43、系统详细设计文档64、各个模块的实现方法描述95、测试数据及期望结果11一、系统描述1、需求实现的功能1.1、录入学生基本信息的功能学生基本信息主要包含:学号、姓名、年龄、出生地、专业、班级总学分,在拔出时,如果数据库已经存在该学号,则不克不及再拔出该学号。

1.2、修改学生基本信息的功能在管理员模式下,只要在表格中选中某个学生,就可以对该学生信息进行修改。

评阅意见:评定成绩:指导老师签名:年 月 日1.3、查询学生基本信息的功能可使用“姓名”对已存有的学生资料进行查询。

1.4、删除学生基本信息的功能在管理员模式下,只要选择表格中的某个学生,就可以删除该学生。

1.5、用户登陆用分歧的登录权限可以进入分歧的后台界面,从而实现权限操纵。

1.6、用户登陆信息设置可以修改用户登陆密码2、设计目的学生信息管理系统是一个教育单位不成缺少的部分。

一个功能齐全、简单易用的信息管理系统不单能有效地减轻学校相关工作人员的工作负担,它的内容对于学校的决策者和管理者来说都至关重要。

所以学生信息管理系统应该能够为用户提供充足的信息和快捷的查询手段。

但一直以来人们使用传统人工的方式管理文件档案、统计和查询数据,这种管理方式存在着许多缺点,如:效率低、保密性差、人工的大量浪费;另外时间一长,将发生大量的文件和数据,这对于查找、更新和维护都带来了很多困难。

随着科学技术的不竭提高,计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。

作为计算机应用的一部分,使用计算机对学校的各类信息进行管理,具有手工管理无法比较的优点。

例如:检索迅速、查询方便、效率高、可靠性好、存储量大、保密性好、寿命长、成本低等。

学生信息管理系统java代码

学生信息管理系统java代码以下是一个简单的学生信息管理系统Java代码,包括增删改查等基本功能实现:```javaimport java.util.ArrayList;import java.util.Scanner;class Student{ // 学生类private String sno; // 学号private String name; // 姓名private String sex; // 性别private int age; // 年龄public Student(String sno, String name, String sex, int age) { // 构造函数this.sno = sno; = name;this.sex = sex;this.age = age;}@Overridepublic String toString() { // 输出学生信息return "学号:" + sno + ", 姓名:" + name + ", 性别:" + sex + ", 年龄:" + age;}// Getter和Setter方法public String getSno() {return sno;}public void setSno(String sno) {this.sno = sno;}public String getName() {return name;}public void setName(String name) { = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}}public class StudentManagementSystem { // 学生信息管理系统static ArrayList<Student> students = new ArrayList<>(); // 学生列表static Scanner scanner = new Scanner(System.in);public static void main(String[] args) {while (true) {System.out.println("请输入命令(1.新增,2.查询,3.修改,4.删除,5.退出):");int command = scanner.nextInt();switch (command) {case 1: // 新增学生addStudent();break;case 2: // 查询学生queryStudent();break;case 3: // 修改学生updateStudent();break;case 4: // 删除学生deleteStudent();break;case 5: // 退出程序return;default:System.out.println("无效命令!");}}}public static void addStudent() { // 新增学生System.out.println("请输入学号:");String sno = scanner.next();System.out.println("请输入姓名:");String name = scanner.next();System.out.println("请输入性别:");String sex = scanner.next();System.out.println("请输入年龄:");int age = scanner.nextInt();Student student = new Student(sno, name, sex, age);students.add(student);System.out.println("新增学生信息成功!");}public static void queryStudent() { // 查询学生System.out.println("请输入学号:");String sno = scanner.next();for (int i = 0; i < students.size(); i++) {if (students.get(i).getSno().equals(sno)) {System.out.println(students.get(i).toString()); return;}}System.out.println("未找到该学生信息!");}public static void updateStudent() { // 修改学生System.out.println("请输入学号:");String sno = scanner.next();for (int i = 0; i < students.size(); i++) {if (students.get(i).getSno().equals(sno)) {System.out.println("请输入新姓名:");String name = scanner.next();System.out.println("请输入新性别:");String sex = scanner.next();System.out.println("请输入新年龄:");int age = scanner.nextInt();students.get(i).setName(name);students.get(i).setSex(sex);students.get(i).setAge(age);System.out.println("修改学生信息成功!");return;}}System.out.println("未找到该学生信息!");}public static void deleteStudent() { // 删除学生System.out.println("请输入学号:");String sno = scanner 。

教学管理系统java源代码_教学管理系统java源代码.doc

教学管理系统java源代码_教学管理系统java源代码.doc 教学管理系统java源代码教学管理系统java源代码篇⼀:java学⽣管理系统源代码import java.io.Serializable;public class Course implements Serializable{private String courseName;private int courseGrade;Course(){courseName=null;courseGrade=0;}public void setCourseNameValue(String ss){this.courseName=ss;}public void setCourseGradeValue(int dd){this.courseGrade=dd;}public String getCourseNameValue(){return this.courseName;}public int getCourseGradeValue(){return this.courseGrade;}public boolean equals(Object o) {if (o == null){ return false;}else {if (o instanceof Course) {Course rec = (Course) o;if (this.courseName.equals(rec.getCourseNameValue())) {return true;}}return false;}---------------------------------------------------------------------------------------------------------------import java.io.Serializable;import java.util.Arrays;import java.util.LinkedList;import java.util.List;public class Student implements Serializable, Comparable{private String studentName;private int studentId;//private int studentCourseAmount=4;private LinkedList courseList;Student(){studentName=null;studentId=0;courseList=new LinkedList();}public void setStudentNameValue(String name){//确定学⽣名称this.studentName=name;}public void setStudentIdValue(int id){//确定学⽣学号this.studentId=id;}public void setStudentCourseList(LinkedList list){//传⼊课程链listthis.courseList=list;// System.out.println(例:0916 张磊 语⽂98 数学67); }public void setCourseGrade(Object o){//将与学科o同名的学科的成绩改为o的成绩for(int i=0;ithis.courseList.size();i++){ Course obj=new Course();obj=(Course) this.courseList.get(i);if(obj.equals(o)){Course res=(Course) o;obj.setCourseGradeValue(res.getCourseGradeValue());}public String getStudentNameValue(){//取得学⽣姓名return this.studentName;}public int getStudentId(){//取得学⽣学号return this.studentId;}public LinkedList getstudentCourseList(){//得到成绩链的⾸地址return this.courseList;}public long。

学生信息管理系统源代码java

学生学籍管理系统程序源代码目录1.Client.java (2)2.LoginGUI.java (2)3.AdminGUI.java (6)4.StudentGUI.java (14)5.Select.java (17)6.UpdateAndInsert.java (24)7.Delete.java (27)8.Student.java (29)9.Administrator.java (31)1 / 32程序源代码学生学籍管理系统1.Client.java/*程序入口*/ package ms;public class Client {public static void main(String[] args) {LoginGUI lg=new LoginGUI(); lg.login(); } }2.LoginGUI.java/*登陆主窗口*/ package ms; import java.awt.BorderLayout; import java.awt.Choice; import java.awt.GridLayout; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; importjava.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; importjavax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel; public class LoginGUI {JFrame log=null; //登陆主窗口JPanel jPanel1=null; //用于存放用户名、密码、登录方式标签JPanel jPanel2=null; //用于存放用户名、密码输入框和登录方式选择框JPanel jPanel3=null; //用于存放登陆、退出按钮JLabel jLabel1=null; //用于存放用户名标签JLabel jLabel2=null; //用于存放密码标签JLabel jLabel3=null; //用于存放登录方式标签JLabel jLabel4=null; //学生管理系统登陆标签TextField t1=null; //用于存放用户名输入TextField t2=null; //用于存放密码输入2 / 32程序源代码学生学籍管理系统Choice c=null; //用于存放登录方式选择JButton jB1=null; //登陆按钮JButton jB2=null; //退出按钮String UserName=null; //存放用户输入的用户名String UserPassword=null; //存放用户输入的密码int UserLimit=-1; //存放用户选择登陆权限public LoginGUI() { super();桴獩氮杯?渠睥?牆浡?学生学籍管理系统); this.jPanel1=new JPanel(); this.jPanel2=new JPanel(); this.jPanel3=new JPanel(); ?扡汥?敮??扡汥尨用户名); ?扡汥?敮??扡汥尨密码); ?扡汥?敮??扡汥尨登录方式); jLabel4=new JLabel(new ImageIcon(image/login.jpg)); t1=new TextField(); t2=new TextField();c=new Choice(); //创建一个登录方式下拉选择框?摡?学生登陆); ?摡?管理员登陆); ??敮??瑵潴?登陆); //创建登陆按钮??敮??瑵潴?退出); //创建退出按钮} public void login() { BorderLayout border=new BorderLayout(); border.setVgap(15); border.setHgap(10);log.setLayout(border); //设置登陆主窗口布局管理器为BorderLayout log.add(jPanel1, BorderLayout.WEST); log.add(jPanel2, BorderLayout.CENTER); log.add(jPanel3, BorderLayout.SOUTH);log.add(jLabel4,BorderLayout.NORTH); jPanel1.setLayout(new GridLayout(3,1,30,20)); //3行1列jPanel2.setLayout(new GridLayout(3,1,30,20)); jPanel3.setLayout(new GridLayout(1,2,10,30));3 / 32程序源代码学生学籍管理系统jPanel1.add(jLabel1); //添加三个标签用户名、密码、登陆方式jPanel1.add(jLabel2); jPanel1.add(jLabel3); jPanel2.add(t1);//添加用户名、密码输入文本框登陆方式选择框jPanel2.add(t2); jPanel2.add(c); jPanel3.add(jB1); //添加两个按钮jPanel3.add(jB2); jB1.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e){ erName=LoginGUI.this.t1.getText(); erPassword=LoginGUI.this.t2.getText();erLimit=LoginGUI.this.c.getSelectedIndex();if(erLimit==0) {StudentGUI ll=newStudentGUI(LoginGUI.this.log,erName);Select sel=new Select(); sel.setStudentList();for(int i=0;i<sel.getStudentAllId().size();i++){ if(sel.getStudentAllId().get(i).toString().equals(er Name)&&sel.getStudentAllPassword().get(i).equals(erPa ssword)){log.setVisible(false); ll.studentGo(); }else if(i==sel.getStudentAllId().size()-1) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?潌楧??琮楨?潬?用户名密码错误);} }4 / 32程序源代码学生学籍管理系统}else if(erLimit==1) { AdminGUIadmin=new AdminGUI(LoginGUI.this.log); Select sel=new Select(); sel.setAdminList();for(int i=0;i<sel.getAdminAllId().size();i++){ if(sel.getAdminAllId().get(i).toString().equals(LoginGUI.this.U serName)&&sel.getAdminAllPassword().get(i).equals(er Password)){log.setVisible(false); admin.adminGo(); }else if(i==sel.getAdminAllId().size()-1) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?潌楧??琮楨?潬?用户名密码错误);} } } } });jB2.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {System.exit(0); } }); log.setSize(240,260);log.setLocationRelativeTo(null); log.setResizable(false);log.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) {System.exit(0);5 / 32程序源代码学生学籍管理系统} }); log.setVisible(true); } }3.AdminGUI.java*/ /*管理员登陆图形界面package ms; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.TextArea; importjava.awt.TextField;import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; importjava.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; importjavax.swing.JFrame; import javax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel; public class AdminGUI {管理员登陆主窗口JDialog log=null;// jp5 用于存放管理员登陆标签和JPanel jp1=null;// 删除按钮增加JPanel jp2=null;// 用于存放查询修改jp5用于存放信息块JPanel jp3=null;//和按钮删除JPanel jp4=null;//用于存放修改插入用于存放请输入学号文本框JPanel jp5=null;// JLabeljadminLog=null; // 管理员登陆标签请输入学号标签JLabel jLabel=null; // 文本框TextField tf=null; //请输入学号JButton jb1=null;//查询按钮JButton jb2=null;//按钮修改按钮增加JButton jb3=null;// 删除按钮JButton jb4=null;// JButton jb5=null; // 列出全部学生信息TextAreata=null;//信息文本框32 / 6程序源代码学生学籍管理系统JLabel jl=null; //用于站位String id=null; // 用于保存用户输入查询学号TextField[] jtf = new TextField[9] ; JDialog jdialog=null;public AdminGUI(JFrame log) {super();桴獩氮杯?渠睥?楄污杯氨杯尬管理员登陆,true); jp1=new JPanel();jp2=new JPanel(); jp3=new JPanel(); jp4=new JPanel(); jp5=new JPanel(); jadminLog=new JLabel(newImageIcon(image/admin.jpg)); ?扡汥渽睥?慌敢?请输入学号); tf=new TextField(); 扪?敮??瑵潴?查询); 扪?敮??瑵潴?修改); 扪?敮??瑵潴?增加); 扪?敮??瑵潴?删除); 扪?敮??瑵潴?列出全部学生信息); 慴渽睥吠硥?敲?点击查询按钮将在此显示查询信息); jl=new JLabel(); } public void adminGo() { BorderLayout bl=new BorderLayout(); bl.setVgap(30); bl.setHgap(30); log.setLayout(bl);log.add(jp1,BorderLayout.NORTH); BorderLayout bl1=new BorderLayout(); bl1.setVgap(20); jp1.setLayout(bl1);jp1.add(jadminLog,BorderLayout.CENTER); jp5.setLayout(newGridLayout(1,2,200,200)); jp5.add(jLabel); jp5.add(tf);32 / 7程序源代码学生学籍管理系统log.add(jp2,BorderLayout.WEST);jp2.setLayout(new GridLayout(2,1,200,300)); jp2.add(jb1);jp2.add(jb5); log.add(jp3,BorderLayout.CENTER);jp3.setLayout(new BorderLayout(10, 10));jp3.add(jp5,BorderLayout.NORTH); jp3.add(ta);jp5.setLayout(new GridLayout(1,5,10,10)); jp5.add(jLabel);jp5.add(tf); log.add(jp4,BorderLayout.SOUTH);jp4.setLayout(new GridLayout(1,3,200,30)); jp4.add(jb2);jp4.add(jb3); jp4.add(jb4); log.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {System.exit(0); } }); jb1.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {AdminGUI.this.id=AdminGUI.this.tf.getText(); Select sel=new Select();sel.selectStudent(AdminGUI.this.id); if(sel.getStudent()!=null) {Student student=sel.getStudent();摁業??琮楨?慴献瑥敔瑸尨学号屜屴瑜?姓名屜屴瑜?性别屜屴瑜?出生日期屜屴瑜?民族屜屴瑜?籍贯屜屴瑜?专业屜屴瑜?班级屜屴瑜?联系电话屜屴瑜?密码\t\t); AdminGUI.this.ta.append(\+student.getId()+\ \t+student.getName()+\ \t+student.getSex()+\ \t+student.getBornDate()+\ \t+student.getNationality()+\ \t+student.getNationality()+\ \t+student.getMaj()+\+student.getCla()+\ \t+student.getTelNum()+\ \t+student.getPa8 / 32程序源代码学生学籍管理系统ssword()+\); } else {摁業??琮楨?慴献瑥敔瑸尨查无此人); } } });jb5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {Select sel=new Select(); sel.selectAllStudent();摁業??琮楨?慴献瑥敔瑸尨学号屜屴瑜?姓名屜屴瑜?性别屜屴瑜?出生日期屜屴瑜?民族屜屴瑜?籍贯屜屴瑜?专业屜屴瑜?班级屜屴瑜?联系电话屜屴瑜?密码\t\t\n);for(int i=0;i<sel.getAllStudent().size();i++) {Student student=sel.getAllStudent().get(i);AdminGUI.this.ta.append(student.getId()+\ \t+student.getName()+\\t+student.getSex()+\ \t+student.getBornDate()+\ \t+student.getNationality()+\ \t+student.getHometown()+\ \t+student.getMaj()+\ +student.getCla()+\\t+student.getTelNum()+\ \t+student.getPassword()+\); } } }); log.setSize(850,580);log.setLocationRelativeTo(null); log.setResizable(false);jb3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ jdialog=new JDialog(AdminGUI.this.log); String[] str=new 瑓楲杮嵛屻姓名?性别?出生日期?民族?籍贯?专业?班级?联系电话?密码};JLabel[] jlabel=new JLabel[9]; for(int i=0;i<9;i++)9 / 32程序源代码学生学籍管理系统{jlabel[i]=new JLabel(str[i]); jtf[i]=new TextField(); }JPanel jpanel1=new JPanel(); JPanel jpanel2=new JPanel(); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨确定); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨取消); jdialog.setLayout(new BorderLayout());jdialog.add(jpanel1,BorderLayout.CENTER);jdialog.add(jpanel2,BorderLayout.SOUTH);jpanel1.setLayout(new GridLayout(9,2,10,10)); for(int i=0;i<9;i++) {jpanel1.add(jlabel[i]); jpanel1.add(jtf[i]); } jpanel2.add(jbutton1); jpanel2.add(jbutton2);jbutton1.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {Student student=new Student();student.setName(AdminGUI.this.jtf[0].getText());student.setSex(AdminGUI.this.jtf[1].getText());student.setBornDate(AdminGUI.this.jtf[2].getText()); student.setNationality(AdminGUI.this.jtf[3].getText()); student.setHometown(AdminGUI.this.jtf[4].getText());student.setMaj(AdminGUI.this.jtf[5].getText()); student.setCla(AdminGUI.this.jtf[6].getText());student.setTelNum(AdminGUI.this.jtf[7].getText()); student.setPassword(AdminGUI.this.jtf[8].getText()); UpdateAndInsert up=new UpdateAndInsert();if(up.insertStudent(student)==true) {32 / 10程序源代码学生学籍管理系统佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?添加成功); } jdialog.dispose(); } });jbutton2.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {jdialog.dispose(); } });jdialog.setSize(500,400);jdialog.setLocationRelativeTo(null); jdialog.setResizable(false); jdialog.setVisible(true); } }); jb4.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {if(new Delete().delete(AdminGUI.this.tf.getText())==true) {佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?刪除成功);}else 佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?刪除失敗); } }); jb2.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {Select sel=new Select();AdminGUI.this.id=AdminGUI.this.tf.getText();sel.selectStudent(AdminGUI.this.tf.getText());11 / 32程序源代码学生学籍管理系统Student student=sel.getStudent(); if(student==null) {佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?请检查输入的学号); } else {jdialog=new JDialog(AdminGUI.this.log); String[] str=new瑓楲杮嵛屻姓名?性别?出生日期?民族?籍贯?专业?班级?联系电话?密码};JLabel[] jlabel=new JLabel[9]; for(int i=0;i<9;i++) {jlabel[i]=new JLabel(str[i]); } jtf[0]=new TextField(student.getName()); jtf[1]=newTextField(student.getSex());jtf[2]=new TextField(student.getBornDate()); jtf[3]=new TextField(student.getNationality()); jtf[4]=newTextField(student.getHometown()); jtf[5]=newTextField(student.getMaj()); jtf[6]=new TextField(student.getCla());jtf[7]=new TextField(student.getTelNum()); jtf[8]=new TextField(student.getPassword()); JPanel jpanel1=new JPanel(); JPanel jpanel2=new JPanel(); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨确定); ?瑵潴?扪瑵潴?渽睥?畂瑴湯尨取消);jdialog.setLayout(new BorderLayout());jdialog.add(jpanel1,BorderLayout.CENTER);jdialog.add(jpanel2,BorderLayout.SOUTH); jpanel1.setLayout(new GridLayout(9,2,10,10)); for(int i=0;i<9;i++) {jpanel1.add(jlabel[i]); jpanel1.add(jtf[i]); }jpanel2.add(jbutton1); jpanel2.add(jbutton2);jbutton1.addActionListener(new ActionListener()12 / 32程序源代码学生学籍管理系统{ @Overridepublic void actionPerformed(ActionEvent e) {Student student=new Student(Integer.parseInt(AdminGUI.this.id), jtf[0].getText(), jtf[1].getText(), jtf[2].getText(), jtf[3].getText(),jtf[4].getText(), jtf[5].getText(), jtf[6].getText(), jtf[7].getText(),jtf[8].getText());UpdateAndInsert up=new UpdateAndInsert();if(up.updateStudent(student)==true) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?摁業??琮楨?潬?更改成功);; }jdialog.dispose(); } });jbutton2.addActionListener(new ActionListener(){ @Overridepublic void actionPerformed(ActionEvent e) {jdialog.dispose(); } });jdialog.setSize(500,400);jdialog.setLocationRelativeTo(null); jdialog.setResizable(false); jdialog.setVisible(true); } } });log.setVisible(true); } }13 / 32程序源代码学生学籍管理系统4.StudentGUI.java*/ /*学生操作图形界面package ms; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.TextField;import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import java.awt.event.WindowAdapter; importjava.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; importjavax.swing.JFrame; import javax.swing.JLabel;import javax.swing.JOptionPane; import javax.swing.JPanel; public class StudentGUI {学生登入类主窗口JDialog log=null;// 用于存放登入块JPaneljp1=null;// JPanel jp2=null;// 用于存放信息块用于密码存放修改块JPanel jp3=null;// 用于存放我的信息按钮JPanel jp4=null;// JLabel jl1=null;// 学生登入标签学号标签JLabel jl2=null;// 学生姓名标签JLabeljl3=null;// 性别标签JLabel jl4=null;// 出生日期标签JLabel jl5=null;// JLabel jl6=null;//民族标签JLabel jl7=null;// 籍贯标签JLabel jl8=null;// 专业标签班级标签JLabel jl9=null;// JLabel jl10=null;// 联系电话标签请输入密码标签JLabel jl11=null;// JButton jb1=null;//我的信息按钮JButton jb2=null;//密码修改按钮TextField t1=null;//学号文本框学生姓名文本框TextField t2=null;// TextField t3=null;//性别文本框出生日期文本框TextField t4=null;//32 / 14程序源代码学生学籍管理系统TextField t5=null;//民族文本框籍贯文本框TextField t6=null;//专业文本框TextField t7=null;// TextField t8=null;//班级文本框联系电话文本框TextField t9=null;// TextField t10=null;//密码文本框存放密码输入框JPanel jp5=new JPanel();// String id=null;public StudentGUI(JFrame log,String str) {super();桴獩氮杯?渠睥?楄污杯氨杯尬学生登入,true); jp1=new JPanel();jp2=new JPanel(); jp3=new JPanel(); jp4=new JPanel();jl1=new JLabel(new ImageIcon(image/student.jpg)); :); 汪?敮??扡汥尨学号学生姓名:); 汪?敮??扡汥尨性别:); 汪?敮??扡汥尨出生日期汪?敮??扡汥尨:); 民族:); 汪?敮??扡汥尨汪?敮??扡汥尨籍贯:); 汪?敮??扡汥尨专业:); :); 汪?敮??扡汥尨班级:); 联系电话汪?渽睥?慌敢? :);请输入新密码汪?渽睥?慌敢? ); 我的信息扪?敮??瑵潴? ); 扪?敮??瑵潴? 密码修改t1=new T extField(); t2=new TextField(); t3=new TextField(); t4=new TextField(); t5=new TextField(); t6=new TextField(); t7=new TextField(); t8=new TextField(); t9=new TextField(); t10=new TextField(); this.id=str; } public void studentGo() {BorderLayout bl=new BorderLayout(); bl.setHgap(30);bl.setVgap(30);32 / 15程序源代码学生学籍管理系统log.setLayout(bl);log.add(jp1,BorderLayout.NORTH);//将登入块信息块密码修改块放入主窗口log.add(jp2,BorderLayout.CENTER);log.add(jp3,BorderLayout.SOUTH); log.add(jp4,BorderLayout.WEST);jp1.add(jl1,BorderLayout.CENTER); jp2.setLayout(newGridLayout(5,2,20,10)); jp2.add(jl2); jp2.add(t1); jp2.add(jl3);jp2.add(t2); jp2.add(jl4); jp2.add(t3); jp2.add(jl5); jp2.add(t4);jp2.add(jl6); jp2.add(t5); jp2.add(jl7); jp2.add(t6); jp2.add(jl8); jp2.add(t7); jp2.add(jl9); jp2.add(t8); jp2.add(jl10); jp2.add(t9); jp4.add(jb1); BorderLayout bl1=new BorderLayout();bl1.setHgap(38); jp3.setLayout(bl1);jp3.add(jb2,BorderLayout.WEST);jp3.add(jp5,BorderLayout.CENTER); jp5.setLayout(new GridLayout()); jp5.add(jl11); jp5.add(t10);jb1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {Select sel=new Select(); sel.selectStudent(id);Student student=sel.getStudent();t1.setText(new Integer(student.getId()).toString());t2.setText(student.getName()); t3.setText(student.getSex());32 / 16程序源代码学生学籍管理系统t4.setText(student.getBornDate());t5.setText(student.getNationality());t6.setText(student.getHometown()); t7.setText(student.getMaj());t8.setText(student.getCla());t9.setText(student.getTelNum()); } });jb2.addActionListener(new ActionListener() { @Overridepublic void actionPerformed(ActionEvent e) {String password=StudentGUI.this.t10.getText(); UpdateAndInsert up=new UpdateAndInsert();if(up.updatePassword(id, password)==true) { 佊瑰潩偮湡?桳睯敍獳条?慩潬?瑓摵湥??琮楨?潬? 修改成功); } } });log.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {System.exit(0); } }); log.setSize(550,420);log.setLocationRelativeTo(null); log.setResizable(false);log.setVisible(true); } }5.Select.java/* 查询类包括查询的各种方法*/ package ms;import java.sql.*; import java.util.LinkedList;17 / 32程序源代码学生学籍管理系统public class Select {private LinkedList<Integer> studentAllId=null;private LinkedList<String> studentAllPassword=null; private LinkedList<Integer> adminAllId=null;private LinkedList<String> adminAllPassword=null; private Student student=null;private LinkedList<Student> allStudent=null; // 定义MySQL的数据库驱动程序public static final String DBDRIVER =org.gjt.mm.mysql.Driver ; // 定义MySQL数据库的连接地址public static final String DBURL =jdbc:mysql://localhost:3306/studentMS ; 数据库的连接用户名// MySQLpublic static final String DBUSER =oot ; 数据库的连接密码// MySQLpublic static final String DBPASS = systemout ; public Select() {super();this.studentAllId = new LinkedList<Integer>();this.studentAllPassword = new LinkedList<String>(); this.adminAllId = new LinkedList<Integer>();this.adminAllPassword = new LinkedList<String>();this.allStudent = new LinkedList<Student>(); } public LinkedList<Integer> getStudentAllId() {return studentAllId; } public LinkedList<String> getStudentAllPassword() {return studentAllPassword; }public LinkedList<Integer> getAdminAllId() {return adminAllId; }public LinkedList<String> getAdminAllPassword() {return adminAllPassword; }public Student getStudent() {32 / 18程序源代码学生学籍管理系统return student; }public LinkedList<Student> getAllStudent() {return allStudent; } public void setStudentList() //设置studentAllId 和studentAllPassword {Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = select id,password from student; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn =DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; }catch(SQLE xception e){ e.printStackTrace() ; } try {stmt = conn.createStatement() ; //得到stmt对象用于执行sql语句} catch (SQLException e1) { e1.printStackTrace(); } try { rs = stmt.executeQuery(sql) ;//保存sql查询结果} catch (SQLException e1) {e1.printStackTrace(); } try {while(rs.next()) {studentAllId.add(rs.getInt(1));studentAllPassword.add(rs.getString(2)); }} catch (SQLException e1) {e1.printStackTrace();19 / 32程序源代码学生学籍管理系统} try{rs.close() ; stmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; } } public void setAdminList() { Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = select id,password from admin; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn =DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; }catch(SQLE xception e){ e.printStackTrace() ; } try {stmt = conn.createStatement() ; //得到stmt对象用于执行sql语句} catch (SQLException e1) {e1.printStackTrace(); } try {rs = stmt.executeQuery(sql) ;//保存sql查询结果} catch (SQLException e1) {e1.printStackTrace(); } try {while(rs.next()) {adminAllId.add(rs.getInt(1));adminAllPassword.add(rs.getString(2)); }} catch (SQLException e1) {20 / 32程序源代码学生学籍管理系统e1.printStackTrace(); } try{rs.close() ; stmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; } } public boolean selectStudent(String str) {Connection conn = null ; // 数据库连接PreparedStatement pstmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = selectname,sex,bornDate,nationality,hometown,maj,cla,telNum,password +rom student where id=?; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn =DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; }catch(SQLE xception e){ e.printStackTrace() ; } try {pstmt = conn.prepareStatement(sql) ; //得到stmt对象用于执行sql语句} catch (SQLException e1) { e1.printStackTrace(); } try {pstmt.setString(1, str); } catch (SQLException e2) {e2.printStackTrace(); } try {rs = pstmt.executeQuery() ;//保存sql查询结果} catch (SQLException e1) {e1.printStackTrace(); }21 / 32程序源代码学生学籍管理系统try {while(rs.next()) {student=new Student(Integer.parseInt(str), rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4),rs.getString(5), rs.getString(6), rs.getString(7),rs.getString(8), rs.getString(9)); }} catch (SQLException e1) {e1.printStackTrace(); } try{rs.close() ; pstmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; }if(student !=null) {return true; } else {return false; } } public void selectAllStudent(){ Connection conn = null ; // 数据库连接PreparedStatement pstmt = null ; // 数据库的操作对象ResultSet rs = null ; // 保存查询结果String sql = select * +rom student; try{Class.forName(DBDRIVER) ; // 加载驱动程序}catch(ClassNotFoundException e){ e.printStackTrace() ; }try{conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;32 / 22程序源代码学生学籍管理系统}catch(SQLException e){ e.printStackTrace() ; } try {pstmt = conn.prepareStatement(sql) ; //得到stmt对象用于执行sql语句} catch (SQLException e1) { e1.printStackTrace(); }try {rs = pstmt.executeQuery() ;//保存sql 查询结果} catch (SQLException e1) {e1.printStackTrace(); } try {while(rs.next()) {student=new Student(rs.getInt(1), rs.getString(2),rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6), rs.getString(7), rs.getString(8),rs.getString(9), rs.getString(10));allStudent.add(student); }} catch (SQLException e1) {e1.printStackTrace(); } try{rs.close() ; pstmt.close() ;conn.close() ; // 数据库关闭}catch(SQLExceptione){ e.printStackTrace() ; } } }32 / 23程序源代码学生学籍管理系统6.UpdateAndInsert.java/*修改&&插入类定义了修改和插入的所有方法*/ package ms; import java.sql.Connection; import java.sql.DriverManager; importjava.sql.SQLException; import java.sql.Statement; public class UpdateAndInsert {// 定义MySQL的数据库驱动程序public static final String DBDRIVER = org.gjt.mm.mysql.Driver ; // 定义MySQL数据库的连接地址public static final String DBURL = jdbc:mysql://localhost:3306/studentMS ; // MySQL数据库的连接用户名public static final String DBUSER =oot ; // MySQL数据库的连接密码public static final String DBPASS = systemout ; public boolean insertStudent (Student student) { String name=student.getName(); String sex=student.getSex(); String bornDate=student.getBornDate(); Stringnationality=student.getNationality(); Stringhometown=student.getHometown(); String maj=student.getMaj(); String cla=student.getCla();String telNum=student.getTelNum(); Stringpassword=student.getPassword(); Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作try { Class.forName(DBDRIVER) ;} catch (ClassNotFoundException e) {// TODO Auto-generated catch block e.printStackTrace(); } // 加载驱动程序String sql = INSERT INTOstudent(name,sex,bornDate,nationality,hometown,maj,cla,telNum,passw ord) +VALUES24 / 32程序源代码学生学籍管理系统('+name+','+sex+','+bornDate+','+nationality+','+hometown+','+maj+', '+cla+','+telNum+','+password+'); try {conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace();对象实例化} Statement // try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();// } 执行数据库更新操作try {关闭操作// stmt.close() ; conn.close() ;} catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); // 数据库关闭} return true; } public boolean updateStudent(Student student) {Select sel=new Select(); if(sel.selectStudent(newInteger(student.getId()).toString())==false) {return false; }数据库连接// Connection conn = null ; // 数据库操作Statement stmt = null ; String name=student.getName(); Stringsex=student.getSex();32 / 25程序源代码学生学籍管理系统String bornDate=student.getBornDate(); Stringnationality=student.getNationality(); String hometown=student.getHometown(); String maj=student.getMaj(); Stringcla=student.getCla();String telNum=student.getTelNum(); Stringpassword=student.getPassword(); String sql=UPDATE student SET name='+name+',sex='+sex+',bornDate='+bornDate+',nationality='+na tionality+',hometown='+hometown+',maj='+maj+',cla='+cla+',telNum ='+telNum+',password='+password+' WHERE id=+student.getId() ;try {= conn DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e1) {// TODO Auto-generated catch block e1.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace();Statement// 实例化对象} try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();// } 执行数据库更新操作try {// 关闭操作stmt.close() ; // 数据库关闭conn.close() ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return true; }32 / 26程序源代码学生学籍管理系统public boolean updatePassword(String id,String newPassword) { Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作String sql=UPDATE student SETpassword='+newPassword+' WHERE id=+id ; try {conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e1) {// TODO Auto-generated catch block e1.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace();Statement 对象// 实例化} try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();执行数据库更新操作} // try {关闭操作// stmt.close() ; conn.close() ; 数据库关闭// } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return true; } }7.Delete.java/* 删除类*/* 定义了删除的所有方法32 / 27程序源代码学生学籍管理系统package ms; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Delete {// 定义MySQL的数据库驱动程序public static final String DBDRIVER = org.gjt.mm.mysql.Driver ; // 定义MySQL数据库的连接地址public static final String DBURL = jdbc:mysql://localhost:3306/studentMS ; //MySQL数据库的连接用户名public static final String DBUSER =oot ; // MySQL数据库的连接密码public static final String DBPASS = systemout ; public boolean delete (String str) {Select sel=new Select();if(sel.selectStudent(str)==false) {return false; }Connection conn = null ; // 数据库连接Statement stmt = null ; // 数据库操作int id = Integer.parseInt(str) ; try {Class.forName(DBDRIVER) ;} catch (ClassNotFoundException e) {// TODO Auto-generated catch block e.printStackTrace(); } // 加载驱动程序String sql = DELETE FROM student WHERE id=+id ; try {conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); }try {stmt = conn.createStatement() ; } catch (SQLException e) {// TODO Auto-generated catch block28 / 32程序源代码学生学籍管理系统e.printStackTrace();} // 实例化Statement对象try {stmt.executeUpdate(sql) ; } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace();} // 执行数据库更新操作try {stmt.close() ; // 关闭操作conn.close() ; // 数据库关闭} catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } return true; }}8.Student.java/*学生类*/ package ms; public class Student {private int id=0; //用于存放学号private String name=null; //用于存放学生姓名private String sex=null; //用于存放性别private String bornDate=null; //出生年日期private String nationality=null; //民族private String hometown=null; //用于存放籍贯private String maj=null; //用于存放专业private String cla=null; //用于存放班级private String telNum=null; //用于存放联系电话private String password=null; //用于存放密码public Student(int id, String name, String sex, String bornDate, String nationality, String hometown, String maj, String cla, String telNum, String password) { this.id = id; = name; this.sex = sex;this.bornDate = bornDate; this.nationality = nationality;this.hometown = hometown; this.maj = maj;。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

学生学籍管理详细设计学号:____________姓名:____________班级:____________一、设计题目:学生学籍管理二:设计内容:设计GUI学生学籍管理界面,用户可以加入学生信息,并对基本信息进行修改,添加,查询,删除。

三:设计要求:进行简单的学生信息管理。

四:总体设计(1)登陆界面的设计(2)主窗体的设计(3)添加学生信息窗体(4)查询学生信息窗体(5)修改学生信息窗体(6)删除学生信息窗体(7)事件响应的处理五:具体设计(1)程序结构的说明:A.入口程序:student.java;B.登陆界面程序:mainframe.java;C.主窗体程序:interfac.java;D.添加信息窗口程序:tj.java;E.修改信息窗口程序:xg.java;F.查询信息窗口程序:cx.java;G.删除信息窗口程序:sc.java;H.程序数据连接:DatabaseConn.java;(2)程序代码及分析说明A.程序源代码(已提交)B.Student.java是程序的入口。

使登录窗口位于窗口中间,并且不可改变窗口大小。

C.mainframe.java是程序的登陆窗体。

输入用户名和密码(用户名和密码在数据库的password表中)点击“进入系统”,然后登陆界面消失;出现要操作的界面(屏幕左上角)。

D.tj.java是添加信息界面。

添加基本信息后,点击“添加信息”按钮,将信息加入xinxi表中。

E.xg.java是修改信息界面。

输入要修改的学号或姓名(两者数其一或全部输入),并输入所有信息,点击“修改信息”按钮(如果数据库中不存在此学号,则弹出对话框“无此学生信息”),若有则修改。

F.sc.java是删除信息界面。

输入要删除的学生的学号,点击“删除信息”按钮,弹出确认删除对话框,即可删除该生信息。

G.cx.java是查询信息界面。

输入要查询的学生学号,点击“信息查询”按钮,在相应的文本区里显示查询的信息。

H:源代码//student.java:程序的入口。

初始化界面,使主界面位于屏幕中间,且用户不能改变大小//功能:完成程序的执行顺序import javax.swing.UIManager;import java.awt.*;import java.sql.*;//import screenpublic class student{boolean packFrame=false;//JFrame frame=new JFrame();public student(){mainframe frame=new mainframe();if(packFrame){frame.pack();}else{frame.validate();}DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();Dimension frameSize=frame.getSize();if(frameSize.height>screenSize.height){frameSize.height=screenSize.height;}if(frameSize.width>screenSize.width){frameSize.width=screenSize.width;}frame.setLocation((screenSize.width-frameSize.width)/2,(screenSiz e.height-frameSize.height)/2);frame.setVisible(true);}public static void main(String[] args){try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName( ));}catch(Exception e){e.printStackTrace();}new student();}}//数据库连接//package sql.database;import java.sql.*;public class DatabaseConn{private static String user="";private static String password="";private Connection conn=null;private Statement stmt=null;private ResultSet rs=null;static{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动}catch(ClassNotFoundException e){}}//创建数据库连接对象public Connection getConnection(){try{conn=DriverManager.getConnection("jdbc:odbc:stu",user,password);return conn;}catch(SQLException e){return null;}}public Statement createStat(){try{conn=getConnection();stmt=conn.createStatement();return stmt;}catch(SQLException e){return null;}}public ResultSet getRs(String sql){try{conn=getConnection();//...stmt=createStat();rs=stmt.executeQuery(sql);return rs;}catch(SQLException e){return null;}}public void close(){try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(conn!=null)conn.close();}catch(SQLException ex){ex.printStackTrace();}}}//mainframe.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class mainframe extends JFrame implements ActionListener {static mainframe s;static JPanel pan=new JPanel();static JLabel label1 = new JLabel("用户");static JLabel label2 = new JLabel("密码");static JTextField textField1 = new JTextField();static JPasswordField password = new JPasswordField();static JButton button1 = new JButton("进入系统");static JRadioButton radioButton1=new JRadioButton("管理员",true);//“管理员”初始状态被选中static JRadioButton radioButton2=new JRadioButton("学生");static JRadioButton radioButton3=new JRadioButton("教师");ButtonGroup buttonGroup=new ButtonGroup();public mainframe(){JLabel label=new JLabel(new ImageIcon("图片44.jpg"));label.setSize(400,400);pan.add(label);pan.setLayout(null);pan.setSize(400,400);this.setTitle("学籍管理系统");this.setSize(400,400);this.setLayout(null);label1.setBounds(100,25,49,20);textField1.setBounds(155,24,120,20);label2.setBounds(100,62,49,20);password.setBounds(155,61,120,20);button1.setBounds(150,200,101,22);radioButton1.setBounds(105,120,80,20);radioButton2.setBounds(180,120,60,20);radioButton3.setBounds(240,120,60,20);button1.addActionListener(this);buttonGroup.add(radioButton1);buttonGroup.add(radioButton2);buttonGroup.add(radioButton3);this.add(radioButton1);this.add(radioButton2);this.add(radioButton3);this.add(label1);this.add(label2);this.add(textField1);this.add(password);this.add(button1);this.add(pan);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public static void main(String[] args){new mainframe();}public void actionPerformed(ActionEvent e){if(radioButton1.isSelected())//管理员{if(textField1.getText().equals("syc") && password.getText().equals("123")){interfac b=new interfac();this.dispose();//JOptionPane.showMessageDialog(null,"登陆成功");}else if("".equals(textField1.getText()) ||"".equals(password.getText()) ){JOptionPane.showMessageDialog(null,"用户名或密码不能为空");}else{JOptionPane.showMessageDialog(null,"用户名或密码输入有误");}}if(radioButton2.isSelected())//学生{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery("select * from password where 用户名= '"+textField1.getText()+"' and 密码= '"+password.getText()+"'");if(textField1.getText().equals("")||password.getText().equals("")){JOptionPane.showMessageDialog(this,"用户名或密码不可为空!");}else if(rs.next()){ new interfac();}else{JOptionPane.showMessageDialog(this,"您的输入有误");}//stmt.close();}catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}//interface.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;public class interfac extends JFrame implements ActionListener{static JMenuBar jMenuBar = new JMenuBar();//菜单条static JMenu jMenuFile = new JMenu("文件");//菜单项static JMenu jMenuExit = new JMenu("退出");static JMenuItem jMenuItem1 = new JMenuItem("添加信息");//菜单子项 static JMenuItem jMenuItem2 = new JMenuItem("修改信息");static JMenuItem jMenuItem3 = new JMenuItem("信息查询");static JMenuItem jMenuItem4 = new JMenuItem("删除信息");static JLabel label3 = new JLabel("请选择操作项");static JLabel label4 = new JLabel("学籍管理系统");static JButton button2 = new JButton("添加信息");static JButton button3 = new JButton("修改信息");static JButton button4 = new JButton("信息查询");static JButton button5 = new JButton("删除信息");public interfac(){this.setTitle("学籍管理系统");this.setLayout(null);this.setSize(400,400);label3.setBounds(158,92,98,33);label3.setFont(new Font("Dialog",Font.PLAIN,15));label4.setFont(new Font("Dialog",Font.BOLD,20));label4.setBounds(157,37,280,40);button2.setBounds(74,136,97,33);button3.setBounds(226,136,97,33);button4.setBounds(74,185,97,33);button5.setBounds(226,185,97,33);this.add(button2);this.add(button3);this.add(button4);this.add(button5);this.add(label3);this.add(label4);setJMenuBar(jMenuBar);jMenuFile.add(jMenuItem1);//”文件“菜单项中加入子菜单 jMenuFile.add(jMenuItem2);jMenuFile.add(jMenuItem3);jMenuFile.add(jMenuItem4);jMenuBar.add(jMenuFile);//将菜单项加入菜单条jMenuBar.add(jMenuExit);button2.addActionListener(this);//本窗口向按钮事件源注册button3.addActionListener(this);button4.addActionListener(this);button5.addActionListener(this);jMenuItem1.addActionListener(this);//本窗口菜单子项注册jMenuItem2.addActionListener(this);jMenuItem3.addActionListener(this);jMenuItem4.addActionListener(this);jMenuExit.addActionListener(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public static void main(String[] args){interfac a=new interfac();}public void actionPerformed(ActionEvent e) //按钮事件的处理{if(e.getSource()==jMenuExit){System.exit(0);}else if(e.getSource()==jMenuItem1||e.getSource()==button2) {try{tj a=new tj();}catch(Exception ee) {}}else if(e.getSource()==jMenuItem2||e.getSource()==button3){try{xg a=new xg();}catch(Exception ed) {}}elseif(e.getSource()==jMenuItem3||e.getSource()==button4){try{cx a=new cx();}catch(Exception ec){}}elseif(e.getSource()==jMenuItem4||e.getSource()==button5){try{sc a=new sc();}catch(Exception es){}}}}//tj.java 添加界面import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class tj extends JFrame implements ActionListener{static tj s;static JLabel label1 = new JLabel("学号:");static JTextField textField1 = new JTextField("");static JLabel label2 = new JLabel("姓名:");static JTextField textField2 = new JTextField("");static JLabel label3 = new JLabel("性别:");static JTextField textField7=new JTextField("");static JLabel label4 = new JLabel("出生日期:");static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel("政治面貌:");static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel("籍贯");static JTextField textField4 = new JTextField("");static JLabel label7 = new JLabel("系别:");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel("专业:");static JTextField textField5 = new JTextField(""); static JButton button1 = new JButton("增加");public tj(){this.setTitle("增加学生信息");this.setLayout(null);this.setSize(400,400);label1.setBounds(30, 11, 51, 33);textField1.setBounds(86, 16, 74, 22);label2.setBounds(162, 11, 51, 33);textField2.setBounds(192, 16, 44, 22);label3.setBounds(241, 11, 70, 33);textField7.setBounds(275, 15, 50, 25);label4.setBounds(31, 53, 55, 33);textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33);textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33);textField4.setBounds(191, 58, 44, 22);label7.setBounds(30, 94, 50, 33);textField9.setBounds(86,94,74,22);label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22);button1.setBounds(25,241,80,33);button1.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button1);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) throws Exception{tj a= new tj();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e)//事件处理程序{if (e.getSource() == button1){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");if(rs.next()){JOptionPane.showMessageDialog(null,"此学号已经被注册");}else{stmt.execute("insert into xinxi (学号,姓名,性别,出生日期,政治面貌,籍贯,系别,专业) values ('"+textField1.getText()+"','"+textField2.getText()+"','"+textField7.getText()+"','"+textField3.getText()+"','"+textField8.getText()+"','"+textField4.getText()+"','"+textField9.getText()+"','"+textField5.getText()+"')");JOptionPane.showMessageDialog(null,"添加信息成功");}}catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}//xg.java 修改界面import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class xg extends JFrame implements ActionListener{static xg s;static JLabel label1 = new JLabel("学号:");static JTextField textField1 = new JTextField("");static JLabel label2 = new JLabel("姓名:");static JTextField textField2 = new JTextField("");static JLabel label3 = new JLabel("性别:");static JTextField textField7=new JTextField("");static JLabel label4 = new JLabel("出生日期:");static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel("政治面貌:");static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel("籍贯");static JTextField textField4 = new JTextField("");static JLabel label7 = new JLabel("系别:");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel("专业:");static JTextField textField5 = new JTextField(""); static JButton button2=new JButton("修改");public xg(){this.setTitle("修改学生信息");this.setLayout(null);this.setSize(400,400);label1.setBounds(30, 11, 51, 33);textField1.setBounds(86, 16, 74, 22);label2.setBounds(162, 11, 51, 33);textField2.setBounds(192, 16, 44, 22);label3.setBounds(241, 11, 70, 33);textField7.setBounds(275, 15, 50, 25);label4.setBounds(31, 53, 55, 33);textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33);textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33);textField4.setBounds(191, 58, 44, 22);label7.setBounds(30, 94, 50, 33);textField9.setBounds(86,94,74,22);label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22);button2.setBounds(115,241,80,33);button2.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button2);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) throws Exception{xg a=new xg();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e)//事件处理程序{if(e.getSource()==button2){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");if(textField1.getText().trim().equals("")){JOptionPane.showMessageDialog(this,"学号不可为空!");}else if(rs.next()){String updateSql="update xinxi set 学号='"+textField1.getText()+"', 姓名='"+textField2.getText()+"',性别='"+textField7.getText()+"',出生日期='"+textField3.getText()+"',政治面貌='"+textField8.getText()+"',籍贯='"+textField4.getText()+"',系别='"+textField9.getText()+"',专业='"+textField5.getText()+ "'";try{stmt.executeQuery(updateSql);}catch(SQLException se){JOptionPane.showMessageDialog(null,"修改成功");}}}catch(SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}//sc.java 删除界面import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class sc extends JFrame implements ActionListener{static sc s;static JLabel label1 = new JLabel("学号:");static JTextField textField1 = new JTextField("");static JLabel label2 = new JLabel("姓名:");static JTextField textField2 = new JTextField(""); static JLabel label3 = new JLabel("性别:");static JTextField textField7=new JTextField("");static JLabel label4 = new JLabel("出生日期:");static JTextField textField3 = new JTextField(""); static JLabel label5 = new JLabel("政治面貌:");static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel("籍贯");static JTextField textField4 = new JTextField(""); static JLabel label7 = new JLabel("系别:");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel("专业:");static JTextField textField5 = new JTextField(""); static JButton button4=new JButton("删除");public sc() throws Exception{this.setTitle("删除学生信息");this.setLayout(null);this.setSize(400,400);label1.setBounds(30, 11, 51, 33);textField1.setBounds(86, 16, 74, 22);label2.setBounds(162, 11, 51, 33);textField2.setBounds(192, 16, 44, 22);label3.setBounds(241, 11, 70, 33);textField7.setBounds(275, 15, 50, 25);label4.setBounds(31, 53, 55, 33);textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33);textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33);textField4.setBounds(191, 58, 44, 22);label7.setBounds(30, 94, 50, 33);textField9.setBounds(86,94,74,22);label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22);button4.setBounds(295,241,80,33);button4.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button4);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) throws Exception{sc a= new sc();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e)//sc{if (e.getSource() == button4){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");if(textField1.getText().trim().equals("")){JOptionPane.showMessageDialog(this,"学号不可为空!");}else if(rs.next()){JOptionPane.showConfirmDialog(null,"确定要删除该信息嘛?\n删除的信息将不能恢复,继续?","删除确定",JOptionPane.OK_CANCEL_OPTION);//,JOption.QUESTION_MESSAGE)==0;stmt.execute("delete from xinxi where 学号='"+textField1.getText()+"'");JOptionPane.showMessageDialog(null,"删除信息成功!");this.dispose();}else JOptionPane.showMessageDialog(null,"无此学号对应信息","警告",JOptionPane.WARNING_MESSAGE);}catch(Exception ed){JOptionPane.showMessageDialog(s,ed.getMessage());}}}}//cx.java 查询界面import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class cx extends JFrame implements ActionListener{static cx s;static JLabel label1 = new JLabel("学号:");static JTextField textField1 = new JTextField("");static JLabel label2 = new JLabel("姓名:");static JTextField textField2 = new JTextField("");static JLabel label3 = new JLabel("性别:");static JTextField textField7=new JTextField("");static JLabel label4 = new JLabel("出生日期:");static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel("政治面貌:");static JTextField textField8=new JTextField("");static JLabel label6 = new JLabel("籍贯");static JTextField textField4 = new JTextField("");static JLabel label7 = new JLabel("系别:");static JTextField textField9 = new JTextField(""); static JLabel label8 = new JLabel("专业:");static JTextField textField5 = new JTextField(""); static JButton button3=new JButton("查询");public cx() throws Exception{this.setTitle("查询学生信息");this.setLayout(null);this.setSize(400,400);label1.setBounds(30, 11, 51, 33);textField1.setBounds(86, 16, 74, 22);label2.setBounds(162, 11, 51, 33);textField2.setBounds(192, 16, 44, 22);label3.setBounds(241, 11, 70, 33);textField7.setBounds(275, 15, 50, 25);label4.setBounds(31, 53, 55, 33);textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33);textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33);textField4.setBounds(191, 58, 44, 22);label7.setBounds(30, 94, 50, 33);textField9.setBounds(86,94,74,22);label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22);button3.setBounds(205,241,80,33);button3.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button3);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) throws Exception{cx a=new cx();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e){if(e.getSource()==button3){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:stu","sa","");Statement stmt = con.createStatement();ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");if(textField1.getText().trim().equals("")){JOptionPane.showMessageDialog(this,"学号不可为空!");}else if(rs.next()){textField2.setText(rs.getString("姓名"));textField7.setText(rs.getString("性别"));textField3.setText(rs.getString("出生日期"));textField8.setText(rs.getString("政治面貌"));textField4.setText(rs.getString("籍贯"));textField9.setText(rs.getString("系别"));textField5.setText(rs.getString("专业"));}else{JOptionPane.showMessageDialog(this,"无此记录!!!");} }catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}}I. 运行说明在DOS窗口输入javac student.javajava student运行程序。

相关文档
最新文档