├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── README.md ├── lib └── mysql-connector-java-5.1.45-bin.jar ├── src └── 学生信息管理系统 │ ├── AddCourseInfo.java │ ├── AddGradeInfo.java │ ├── AddStuInfo.java │ ├── CourseInfo.java │ ├── CourseInfoSearchCnum.java │ ├── CourseSearchCname.java │ ├── CourseSearchCteacher.java │ ├── CrsBean.java │ ├── Database.java │ ├── DelCourseInfo.java │ ├── DelGradeInfo.java │ ├── DelStuInfo.java │ ├── EditCourseInfo.java │ ├── EditGradeInfo.java │ ├── EditStuInfo.java │ ├── GradeInfo.java │ ├── GrdSearchAllGrade.java │ ├── Main.java │ ├── ResultCourse.java │ ├── ResultGrade.java │ ├── ResultStudent.java │ ├── SelectCourse.java │ ├── StuBean.java │ ├── StuInfo.java │ ├── StuInfoSearchSnum.java │ ├── StuMain.java │ ├── StuSearchScollege.java │ ├── StuSearchSmajor.java │ ├── StuSearchSname.java │ ├── StuSearchSnum.java │ ├── StuSearchSsex.java │ ├── csBean.java │ └── login.java └── 打包好的jar程序 ├── 学生信息管理系统.jar ├── 学生信息管理系统_lib └── mysql-connector-java-5.1.45-bin.jar └── 运行说明.txt /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 学生信息管理系统 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 学生信息管理系统 2 | 3 | ## 简要说明:采用eclipse开发,用jdbc驱动连接mysql,完成操作。。。留做学习和复习备用 4 | 5 | ### 开发功能有,学生信息的增删改查,学生选课的添加,成绩的增删改查 6 | 7 | **运行前windows系统里至少有不低于jdk8的java运行环境,装有mysql数据库软件并建表 8 | 这样就就可以直接运行打包好的jar文件夹里程序了** 9 | ------ 10 | 核心的类:DataBase.java,代码如下 11 | ------ 12 | ```java 13 | /** 14 | * 连接数据库的类 15 | */ 16 | public class Database { 17 | 18 | private Statement stmt=null; 19 | ResultSet rs=null; 20 | private Connection conn=null; 21 | String sql; 22 | String strurl="jdbc:mysql://127.0.0.1:3306/studentsys?characterEncoding=utf8&useSSL=true"; 23 | 24 | public Database(){ 25 | } 26 | 27 | /** 28 | * 打开数据库连接 29 | */ 30 | public void OpenConn()throws Exception{ 31 | try{ 32 | Class.forName("com.mysql.jdbc.Driver"); 33 | conn=DriverManager.getConnection(strurl,"root","5201314qaz,./"); 34 | conn.setAutoCommit(false); 35 | } 36 | catch(Exception e){ 37 | System.err.println("OpenConn:"+e.getMessage()); 38 | e.printStackTrace(); 39 | } 40 | } 41 | 42 | /** 43 | * 执行sql语句,返回结果集rs 44 | */ 45 | public ResultSet executeQuery(String sql){ 46 | stmt = null; 47 | rs=null; 48 | 49 | try{ 50 | 51 | stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); 52 | rs=stmt.executeQuery(sql); 53 | } 54 | catch(SQLException e){ 55 | System.err.println("executeQuery:"+e.getMessage()); 56 | e.printStackTrace(); 57 | } 58 | return rs; 59 | 60 | } 61 | 62 | /** 63 | * 执行sql语句 64 | */ 65 | public int executeUpdate(String sql){ 66 | stmt=null; 67 | rs=null; 68 | int k=0; 69 | try{ 70 | stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); 71 | k=stmt.executeUpdate(sql); 72 | conn.commit(); 73 | } 74 | catch(SQLException e){ 75 | System.err.println("executeUpdate:"+e.getMessage()); 76 | e.printStackTrace(); 77 | } 78 | return k; 79 | } 80 | 81 | public void closeStmt(){ 82 | try{ 83 | stmt.close(); 84 | } 85 | catch(SQLException e){ 86 | System.err.println("closeStmt:"+e.getMessage()); 87 | } 88 | } 89 | 90 | /** 91 | * 关闭数据库连接 92 | */ 93 | public void closeConn(){ 94 | try{ 95 | conn.close(); 96 | } 97 | catch(SQLException ex){ 98 | System.err.println("aq.closeConn:"+ex.getMessage()); 99 | } 100 | } 101 | ``` 102 | -------------------------------------------------------------------------------- /lib/mysql-connector-java-5.1.45-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1065448858/StudentManager/2b456b4f78edac5de8cb94fa86d12dc932d3ceff/lib/mysql-connector-java-5.1.45-bin.jar -------------------------------------------------------------------------------- /src/学生信息管理系统/AddCourseInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | 4 | 5 | import java.awt.event.*; 6 | import java.awt.*; 7 | 8 | /** 9 | * 课程信息管理模块 10 | * 添加新的课程信息 11 | */ 12 | public class AddCourseInfo extends CourseInfo{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | CrsBean getCnum = new CrsBean(); 19 | 20 | public AddCourseInfo() { 21 | this.setTitle("添加课程信息"); 22 | this.setResizable(false); 23 | 24 | cNum.setEditable(true); 25 | 26 | cName.setEditable(true); 27 | cTeacher.setEditable(true); 28 | cPoint.setEditable(true); 29 | cRatio.setEditable(true); 30 | cPlace.setEditable(true); 31 | 32 | //设置运行位置,使对话框居中 33 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 34 | this.setLocation( (int) (screenSize.width - 400) / 2 , 35 | (int) (screenSize.height - 300) / 2 +45); 36 | } 37 | 38 | public void downInit(){ 39 | addInfo.setText("增加"); 40 | addInfo.setFont(new Font("Dialog",0,12)); 41 | downPanel.add(addInfo); 42 | clearInfo.setText("清空"); 43 | clearInfo.setFont(new Font("Dialog",0,12)); 44 | downPanel.add(clearInfo); 45 | eixtInfo.setText("退出"); 46 | eixtInfo.setFont(new Font("Dialog",0,12)); 47 | downPanel.add(eixtInfo); 48 | 49 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 50 | 51 | //添加事件侦听 52 | addInfo.addActionListener(this); 53 | clearInfo.addActionListener(this); 54 | eixtInfo.addActionListener(this); 55 | } 56 | 57 | /** 58 | * 事件处理 59 | */ 60 | public void actionPerformed(ActionEvent e) { 61 | Object obj = e.getSource(); 62 | if (obj == eixtInfo) { //退出 63 | this.dispose(); 64 | } 65 | else if (obj == addInfo) { //增加 66 | cNum.setEnabled(false); 67 | cName.setEditable(false); 68 | cTeacher.setEditable(false); 69 | cPoint.setEditable(false); 70 | cRatio.setEditable(false); 71 | cPlace.setEditable(false); 72 | 73 | addInfo.setEnabled(false); 74 | clearInfo.setEnabled(false); 75 | eixtInfo.setEnabled(false); 76 | 77 | CrsBean addCrs = new CrsBean(); 78 | addCrs.crsAdd(cNum.getText(),cName.getText(), cTeacher.getText(), cPlace.getText(), cPoint.getText(), cRatio.getText()); 79 | 80 | this.dispose(); 81 | 82 | AddCourseInfo aci = new AddCourseInfo(); 83 | aci.downInit(); 84 | aci.pack(); 85 | aci.setVisible(true); 86 | 87 | this.dispose(); 88 | } 89 | else if (obj == clearInfo) { //清空 90 | setNull(); 91 | cNum.setText(""); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/学生信息管理系统/AddGradeInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.event.*; 4 | import java.awt.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 成绩信息管理模块 9 | * 添加新的成绩信息 10 | */ 11 | public class AddGradeInfo extends GradeInfo implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | 17 | public AddGradeInfo() { 18 | this.setTitle("添加成绩信息"); 19 | this.setResizable(false); 20 | 21 | //设置运行位置,使对话框居中 22 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 23 | this.setLocation( (int) (screenSize.width - 400) / 2 , 24 | (int) (screenSize.height - 300) / 2 +45); 25 | } 26 | 27 | public void downInit(){ 28 | addInfo.setText("增加"); 29 | addInfo.setFont(new Font("Dialog",0,12)); 30 | downPanel.add(addInfo); 31 | eixtInfo.setText("退出"); 32 | eixtInfo.setFont(new Font("Dialog",0,12)); 33 | downPanel.add(eixtInfo); 34 | 35 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 36 | 37 | sNum.addActionListener(this); 38 | addInfo.addActionListener(this); 39 | eixtInfo.addActionListener(this); 40 | } 41 | 42 | /** 43 | * 事件处理 44 | */ 45 | @SuppressWarnings("unchecked") 46 | public void actionPerformed(ActionEvent e) { 47 | Object obj = e.getSource(); 48 | 49 | if (obj == addInfo) { //增加 50 | cNum.setEnabled(false); 51 | cName.setEditable(false); 52 | cTeacher.setEditable(false); 53 | Grade.setEditable(false); 54 | sNum.setEditable(false); 55 | sName.setEditable(false); 56 | 57 | addInfo.setEnabled(false); 58 | clearInfo.setEnabled(false); 59 | eixtInfo.setEnabled(false); 60 | 61 | csBean addGrade = new csBean(); 62 | addGrade.csModify(cNum.getText(),(String)sNum.getSelectedItem(),Grade.getText()); 63 | 64 | this.dispose(); 65 | AddGradeInfo agi = new AddGradeInfo(); 66 | agi.downInit(); 67 | agi.pack(); 68 | agi.setVisible(true); 69 | } 70 | else if (obj == eixtInfo) { //退出 71 | this.dispose(); 72 | } 73 | else if (obj == sNum) { //选择学号 74 | 75 | StuBean sN = new StuBean(); 76 | sName.setText(sN.stuSearch((String)sNum.getSelectedItem())[0]); 77 | 78 | if(cName.getItemCount()>0){ 79 | cName.removeAllItems(); 80 | } 81 | 82 | csBean cN = new csBean(); 83 | cReturn = cN.cNameSearch((String)sNum.getSelectedItem()); 84 | 85 | if(cReturn == null){ 86 | cName.removeActionListener(this); 87 | JOptionPane.showMessageDialog(null,"该学生没有选择课程!"); 88 | addInfo.setEnabled(false); 89 | cName.setEnabled(false); 90 | } 91 | else{ 92 | int i = 0; 93 | 94 | for(i = 0; i < (cReturn.length); i++){ 95 | cName.addItem(cReturn[i]); 96 | } 97 | 98 | cName.setEnabled(true); 99 | sNum.setEnabled(false); 100 | cName.setSelectedItem(null); 101 | cName.addActionListener(this); 102 | } 103 | } 104 | else if (obj == cName) { //选择课程号 105 | CrsBean cSname = new CrsBean(); 106 | cNum.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[0]); 107 | cTeacher.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[1]); 108 | addInfo.setEnabled(true); 109 | cName.setEnabled(false); 110 | cName.removeActionListener(this); 111 | } 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/学生信息管理系统/AddStuInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | 4 | import java.awt.event.*; 5 | import java.awt.*; 6 | 7 | /**setNull 8 | * 学生信息管理模块 9 | * 添加新的学生信息 10 | */ 11 | public class AddStuInfo extends StuInfo { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | StuBean getSnum = new StuBean(); 17 | public AddStuInfo() { 18 | this.setTitle("添加学生信息"); 19 | this.setResizable(false); 20 | sNum.setEditable(true); 21 | //sNum.setText(""+getSnum.getStuId()); 22 | 23 | sName.setEditable(true); 24 | sSex.setEditable(true); 25 | sSethnic.setEditable(true); 26 | sBirth.setEditable(true); 27 | sYear.setEditable(true); 28 | sMajor.setEditable(true); 29 | sCollege.setEditable(true); 30 | sHome.setEditable(true); 31 | 32 | //设置运行时窗口的位置 33 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 34 | this.setLocation((screenSize.width - 400) / 2, 35 | (screenSize.height - 300) / 2 + 45); 36 | } 37 | 38 | public void downInit(){ 39 | addInfo.setText("增加"); 40 | addInfo.setFont(new Font("Dialog",0,12)); 41 | downPanel.add(addInfo); 42 | clearInfo.setText("清空"); 43 | clearInfo.setFont(new Font("Dialog",0,12)); 44 | downPanel.add(clearInfo); 45 | eixtInfo.setText("退出"); 46 | eixtInfo.setFont(new Font("Dialog",0,12)); 47 | downPanel.add(eixtInfo); 48 | 49 | //添加事件侦听 50 | addInfo.addActionListener(this); 51 | clearInfo.addActionListener(this); 52 | eixtInfo.addActionListener(this); 53 | 54 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 55 | } 56 | 57 | /** 58 | * 事件处理 59 | */ 60 | public void actionPerformed(ActionEvent e) { 61 | Object obj = e.getSource(); 62 | if (obj == eixtInfo) { //退出 63 | this.dispose(); 64 | } 65 | else if (obj == addInfo) { //增加 66 | 67 | sNum.setEnabled(false); 68 | sName.setEnabled(false); 69 | sSex.setEnabled(false); 70 | sSethnic.setEnabled(false); 71 | sBirth.setEnabled(false); 72 | sYear.setEnabled(false); 73 | sMajor.setEnabled(false); 74 | sCollege.setEnabled(false); 75 | sHome.setEnabled(false); 76 | 77 | addInfo.setEnabled(false); 78 | clearInfo.setEnabled(false); 79 | eixtInfo.setEnabled(false); 80 | 81 | StuBean addStu = new StuBean(); 82 | addStu.stuAdd(sNum.getText(),sName.getText(), sSex.getText(), sBirth.getText(), sHome.getText(), sSethnic.getText(), sYear.getText(), sMajor.getText(), sCollege.getText()); 83 | 84 | this.dispose(); 85 | 86 | AddStuInfo asi = new AddStuInfo(); 87 | asi.downInit(); 88 | asi.pack(); 89 | asi.setVisible(true); 90 | } 91 | else if (obj == clearInfo) { //清空 92 | setNull(); 93 | } 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/学生信息管理系统/CourseInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.awt.event.*; 8 | 9 | /** 10 | * 课程信息综合管理类 11 | * 提供主界面,供其他类继承 12 | */ 13 | public class CourseInfo extends JFrame implements ActionListener{ 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | Container contentPane; 19 | JPanel centerPanel = new JPanel(); 20 | JPanel upPanel = new JPanel(); 21 | JPanel downPanel = new JPanel(); 22 | 23 | //框架的大小 24 | Dimension faceSize = new Dimension(800, 500); 25 | 26 | JLabel jLabel1 = new JLabel(); 27 | JLabel jLabel2 = new JLabel(); 28 | JLabel jLabel3 = new JLabel(); 29 | JLabel jLabel4 = new JLabel(); 30 | JLabel jLabel5 = new JLabel(); 31 | JLabel jLabel6 = new JLabel(); 32 | 33 | JTextField cNum = new JTextField(15); 34 | JTextField cName = new JTextField(15); 35 | JTextField cTeacher = new JTextField(15); 36 | JTextField cPoint = new JTextField(15); 37 | JTextField cRatio = new JTextField(15); 38 | JTextField cPlace = new JTextField(15); 39 | 40 | JButton searchInfo = new JButton(); 41 | JButton addInfo = new JButton(); 42 | JButton modifyInfo = new JButton(); 43 | JButton deleteInfo = new JButton(); 44 | JButton clearInfo = new JButton(); 45 | JButton saveInfo = new JButton(); 46 | JButton eixtInfo = new JButton(); 47 | 48 | GridBagLayout girdBag = new GridBagLayout(); 49 | GridBagConstraints girdBagCon; 50 | public CourseInfo() {this.setSize(faceSize); 51 | //设置标题 52 | //this.setTitle("课程综合信息管理"); 53 | this.setResizable(false); 54 | 55 | try { 56 | Init(); 57 | } 58 | catch(Exception e) { 59 | e.printStackTrace(); 60 | } 61 | } 62 | 63 | public void Init() throws Exception { 64 | contentPane = this.getContentPane(); 65 | contentPane.setLayout(new BorderLayout()); 66 | 67 | //中部面板的布局 68 | centerPanel.setLayout(girdBag); 69 | 70 | jLabel1.setText("课程编码:"); 71 | jLabel1.setFont(new Font("Dialog",0,12)); 72 | girdBagCon = new GridBagConstraints(); 73 | girdBagCon.gridx = 0; 74 | girdBagCon.gridy = 0; 75 | girdBagCon.insets = new Insets(10,10,10,1); 76 | girdBag.setConstraints(jLabel1,girdBagCon); 77 | centerPanel.add(jLabel1); 78 | 79 | girdBagCon = new GridBagConstraints(); 80 | girdBagCon.gridx = 1; 81 | girdBagCon.gridy = 0; 82 | girdBagCon.insets = new Insets(10,1,10,15); 83 | girdBag.setConstraints(cNum,girdBagCon); 84 | centerPanel.add(cNum); 85 | 86 | jLabel2.setText("课程名称:"); 87 | jLabel2.setFont(new Font("Dialog",0,12)); 88 | girdBagCon = new GridBagConstraints(); 89 | girdBagCon.gridx = 2; 90 | girdBagCon.gridy = 0; 91 | girdBagCon.insets = new Insets(10,15,10,1); 92 | girdBag.setConstraints(jLabel2,girdBagCon); 93 | centerPanel.add(jLabel2); 94 | 95 | girdBagCon = new GridBagConstraints(); 96 | girdBagCon.gridx = 3; 97 | girdBagCon.gridy = 0; 98 | girdBagCon.insets = new Insets(10,1,10,10); 99 | girdBag.setConstraints(cName,girdBagCon); 100 | centerPanel.add(cName); 101 | 102 | jLabel3.setText("授课老师:"); 103 | jLabel3.setFont(new Font("Dialog",0,12)); 104 | girdBagCon = new GridBagConstraints(); 105 | girdBagCon.gridx = 0; 106 | girdBagCon.gridy = 1; 107 | girdBagCon.insets = new Insets(10,10,10,1); 108 | girdBag.setConstraints(jLabel3,girdBagCon); 109 | centerPanel.add(jLabel3); 110 | 111 | girdBagCon = new GridBagConstraints(); 112 | girdBagCon.gridx = 1; 113 | girdBagCon.gridy = 1; 114 | girdBagCon.insets = new Insets(10,1,10,15); 115 | girdBag.setConstraints(cTeacher,girdBagCon); 116 | centerPanel.add(cTeacher); 117 | 118 | jLabel4.setText("课程学分:"); 119 | jLabel4.setFont(new Font("Dialog",0,12)); 120 | girdBagCon = new GridBagConstraints(); 121 | girdBagCon.gridx = 2; 122 | girdBagCon.gridy = 1; 123 | girdBagCon.insets = new Insets(10,15,10,1); 124 | girdBag.setConstraints(jLabel4,girdBagCon); 125 | centerPanel.add(jLabel4); 126 | 127 | girdBagCon = new GridBagConstraints(); 128 | girdBagCon.gridx = 3; 129 | girdBagCon.gridy = 1; 130 | girdBagCon.insets = new Insets(10,1,10,10); 131 | girdBag.setConstraints(cPoint,girdBagCon); 132 | centerPanel.add(cPoint); 133 | 134 | jLabel5.setText("课程系数:"); 135 | jLabel5.setFont(new Font("Dialog",0,12)); 136 | girdBagCon = new GridBagConstraints(); 137 | girdBagCon.gridx = 0; 138 | girdBagCon.gridy = 2; 139 | girdBagCon.insets = new Insets(10,10,10,1); 140 | girdBag.setConstraints(jLabel5,girdBagCon); 141 | centerPanel.add(jLabel5); 142 | 143 | girdBagCon = new GridBagConstraints(); 144 | girdBagCon.gridx = 1; 145 | girdBagCon.gridy = 2; 146 | girdBagCon.insets = new Insets(10,1,10,15); 147 | girdBag.setConstraints(cRatio,girdBagCon); 148 | centerPanel.add(cRatio); 149 | 150 | jLabel6.setText("上课地点:"); 151 | jLabel6.setFont(new Font("Dialog",0,12)); 152 | girdBagCon = new GridBagConstraints(); 153 | girdBagCon.gridx = 2; 154 | girdBagCon.gridy = 2; 155 | girdBagCon.insets = new Insets(10,15,10,1); 156 | girdBag.setConstraints(jLabel6,girdBagCon); 157 | centerPanel.add(jLabel6); 158 | 159 | girdBagCon = new GridBagConstraints(); 160 | girdBagCon.gridx = 3; 161 | girdBagCon.insets = new Insets(10,1,10,10); 162 | girdBag.setConstraints(cPlace,girdBagCon); 163 | centerPanel.add(cPlace); 164 | 165 | contentPane.add(centerPanel,BorderLayout.CENTER); 166 | } 167 | 168 | /** 169 | * 下部面板的布局 170 | */ 171 | public void downInit(){ 172 | searchInfo.setText("查询"); 173 | searchInfo.setFont(new Font("Dialog",0,12)); 174 | downPanel.add(searchInfo); 175 | addInfo.setText("增加"); 176 | addInfo.setFont(new Font("Dialog",0,12)); 177 | downPanel.add(addInfo); 178 | modifyInfo.setText("修改"); 179 | modifyInfo.setFont(new Font("Dialog",0,12)); 180 | downPanel.add(modifyInfo); 181 | deleteInfo.setText("删除"); 182 | deleteInfo.setFont(new Font("Dialog",0,12)); 183 | downPanel.add(deleteInfo); 184 | saveInfo.setText("保存"); 185 | saveInfo.setFont(new Font("Dialog",0,12)); 186 | downPanel.add(saveInfo); 187 | clearInfo.setText("清空"); 188 | clearInfo.setFont(new Font("Dialog",0,12)); 189 | downPanel.add(clearInfo); 190 | eixtInfo.setText("退出"); 191 | eixtInfo.setFont(new Font("Dialog",0,12)); 192 | downPanel.add(eixtInfo); 193 | 194 | contentPane.add(downPanel,BorderLayout.SOUTH); 195 | 196 | //添加事件侦听 197 | searchInfo.addActionListener(this); 198 | addInfo.addActionListener(this); 199 | modifyInfo.addActionListener(this); 200 | deleteInfo.addActionListener(this); 201 | saveInfo.addActionListener(this); 202 | clearInfo.addActionListener(this); 203 | eixtInfo.addActionListener(this); 204 | } 205 | 206 | /** 207 | * 事件处理 208 | */ 209 | public void actionPerformed(ActionEvent e) { 210 | Object obj = e.getSource(); 211 | if (obj == searchInfo) { //查询 212 | } 213 | else if (obj == addInfo) { //增加 214 | } 215 | else if (obj == modifyInfo) { //修改 216 | } 217 | else if (obj == deleteInfo) { //删除 218 | } 219 | else if (obj == saveInfo) { //保存 220 | } 221 | else if (obj == clearInfo) { //清空 222 | } 223 | else if (obj == eixtInfo) { //退出 224 | this.dispose(); 225 | } 226 | } 227 | 228 | /** 229 | * 将文本框清空 230 | */ 231 | void setNull(){ 232 | cNum.setText(null); 233 | cName.setText(null); 234 | cTeacher.setText(null); 235 | cPoint.setText(null); 236 | cRatio.setText(null); 237 | cPlace.setText(null); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /src/学生信息管理系统/CourseInfoSearchCnum.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 课程信息管理模块 9 | * 根据课程编号查询课程信息,以供调用者修改或删除 10 | */ 11 | public class CourseInfoSearchCnum extends JDialog implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | String[] s; 18 | //框架的大小 19 | Dimension faceSize = new Dimension(300, 100); 20 | JLabel jLabel1 = new JLabel(); 21 | JComboBox selectCnum; 22 | JButton searchInfo = new JButton(); 23 | 24 | public CourseInfoSearchCnum(JFrame frame) { 25 | super(frame, true); 26 | this.setResizable(false); 27 | try { 28 | Init(); 29 | } 30 | catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | //设置运行位置,使对话框居中 34 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 35 | this.setLocation( (int) (screenSize.width - 400) / 2 , 36 | (int) (screenSize.height - 300) / 2 + 45); 37 | } 38 | 39 | private void Init() throws Exception { 40 | this.setSize(faceSize); 41 | contentPane = this.getContentPane(); 42 | contentPane.setLayout(new FlowLayout()); 43 | 44 | jLabel1.setText("请输入或者选择课程号:"); 45 | jLabel1.setFont(new Font("Dialog",0,12)); 46 | contentPane.add(jLabel1); 47 | 48 | CrsBean getId = new CrsBean(); 49 | s = getId.getAllId(); 50 | 51 | selectCnum = new JComboBox(s); 52 | selectCnum.setSelectedItem(null); 53 | selectCnum.setEditable(true); 54 | selectCnum.setFont(new Font("Dialog",0,12)); 55 | contentPane.add(selectCnum); 56 | 57 | searchInfo.setText("查询"); 58 | searchInfo.setFont(new Font("Dialog",0,12)); 59 | contentPane.add(searchInfo); 60 | 61 | selectCnum.addActionListener(this); 62 | searchInfo.addActionListener(this); 63 | } 64 | 65 | /** 66 | * 事件处理 67 | */ 68 | public void actionPerformed(ActionEvent e) { 69 | Object obj = e.getSource(); 70 | if (obj == selectCnum) { //退出 71 | this.dispose(); 72 | } 73 | else if (obj == searchInfo) { //修改 74 | this.dispose(); 75 | } 76 | } 77 | 78 | /** 79 | * 返回选择的学号 80 | */ 81 | public String getCnum(){ 82 | return (String)this.selectCnum.getSelectedItem(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/学生信息管理系统/CourseSearchCname.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 课程信息查询模块 9 | * 根据课程名称查询课程的信息 10 | */ 11 | public class CourseSearchCname extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | //框架的大小 18 | Dimension faceSize = new Dimension(300, 100); 19 | JLabel jLabel1 = new JLabel(); 20 | JTextField cName = new JTextField(8); 21 | JButton searchInfo = new JButton(); 22 | 23 | 24 | public CourseSearchCname() { 25 | //设置标题 26 | this.setTitle("按课程名称查询"); 27 | this.setResizable(false); 28 | 29 | 30 | try { 31 | Init(); 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | //设置运行位置,使对话框居中 37 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 38 | this.setLocation( (int) (screenSize.width - 400) / 2 , 39 | (int) (screenSize.height - 300) / 2 + 45); 40 | 41 | } 42 | 43 | private void Init() throws Exception { 44 | this.setSize(faceSize); 45 | contentPane = this.getContentPane(); 46 | contentPane.setLayout(new FlowLayout()); 47 | 48 | jLabel1.setText("请输入课程名称: "); 49 | jLabel1.setFont(new Font("Dialog",0,12)); 50 | contentPane.add(jLabel1); 51 | 52 | cName.setText(null); 53 | cName.setFont(new Font("Dialog",0,12)); 54 | contentPane.add(cName); 55 | 56 | searchInfo.setText("确定"); 57 | searchInfo.setFont(new Font("Dialog",0,12)); 58 | contentPane.add(searchInfo); 59 | 60 | searchInfo.addActionListener(this); 61 | 62 | } 63 | 64 | /** 65 | * 事件处理 66 | */ 67 | public void actionPerformed(ActionEvent e) { 68 | Object obj = e.getSource(); 69 | if (obj == searchInfo) { //查询 70 | this.dispose(); 71 | } 72 | } 73 | 74 | 75 | } -------------------------------------------------------------------------------- /src/学生信息管理系统/CourseSearchCteacher.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | import javax.swing.*; 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | 6 | /** 7 | * 课程信息查询模块 8 | * 根据授课教师查询课程的信息 9 | */ 10 | public class CourseSearchCteacher extends JFrame implements ActionListener{ 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | Container contentPane; 16 | //框架的大小 17 | Dimension faceSize = new Dimension(300, 100); 18 | JLabel jLabel1 = new JLabel(); 19 | JTextField cTeacher = new JTextField(8); 20 | JButton searchInfo = new JButton(); 21 | 22 | 23 | public CourseSearchCteacher() { 24 | //设置标题 25 | this.setTitle("按课程名称查询"); 26 | this.setResizable(false); 27 | //设置程序图标 28 | 29 | try { 30 | Init(); 31 | } 32 | catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | //设置运行位置,使对话框居中 36 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 37 | this.setLocation( (int) (screenSize.width - 400) / 2 , 38 | (int) (screenSize.height - 300) / 2 + 45); 39 | 40 | } 41 | 42 | private void Init() throws Exception { 43 | this.setSize(faceSize); 44 | contentPane = this.getContentPane(); 45 | contentPane.setLayout(new FlowLayout()); 46 | 47 | jLabel1.setText("请输入授课教师名称: "); 48 | jLabel1.setFont(new Font("Dialog",0,12)); 49 | contentPane.add(jLabel1); 50 | 51 | cTeacher.setText(null); 52 | cTeacher.setFont(new Font("Dialog",0,12)); 53 | contentPane.add(cTeacher); 54 | 55 | searchInfo.setText("确定"); 56 | searchInfo.setFont(new Font("Dialog",0,12)); 57 | contentPane.add(searchInfo); 58 | 59 | searchInfo.addActionListener(this); 60 | } 61 | 62 | /** 63 | * 事件处理 64 | */ 65 | public void actionPerformed(ActionEvent e) { 66 | Object obj = e.getSource(); 67 | if (obj == searchInfo) { //查询 68 | this.dispose(); 69 | } 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/学生信息管理系统/CrsBean.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.sql.*; 4 | import javax.swing.*; 5 | 6 | /** 7 | * 有关课程信息数据库操作的类 8 | */ 9 | public class CrsBean { 10 | String sql; 11 | ResultSet rs = null; 12 | 13 | String cNum; 14 | String cName; 15 | String cTeacher; 16 | String cPlace; 17 | String cPoint; 18 | String cRatio; 19 | String sNum; 20 | 21 | String colName;//列名 22 | String colValue;//列值 23 | int crsId;//新课程的编号 24 | 25 | /** 26 | * 添加课程信息 27 | */ 28 | public void crsAdd(String num,String name, String teacher, String place, String type, String time){ 29 | 30 | Database DB = new Database(); 31 | this.cNum = num; 32 | this.cName = name; 33 | this.cTeacher = teacher; 34 | this.cPlace = place; 35 | this.cPoint= type; 36 | this.cRatio = time; 37 | 38 | if(cName == null||cName.equals("")){ 39 | JOptionPane.showMessageDialog(null, "请输入课程名称", "错误", JOptionPane.ERROR_MESSAGE); 40 | return; 41 | } 42 | else{ 43 | sql = "insert into course(cnum,cname,cteacher,cplace,cpoint,cratio) values ('"+cNum+"','"+cName+"','"+cTeacher+"','"+cPlace+"','"+cPoint+"','"+cRatio+"')"; 44 | try{ 45 | DB.OpenConn(); 46 | DB.executeUpdate(sql); 47 | JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!"); 48 | 49 | } 50 | catch(Exception e){ 51 | JOptionPane.showMessageDialog(null, "保存失败", "错误", JOptionPane.ERROR_MESSAGE); 52 | } 53 | finally { 54 | DB.closeStmt(); 55 | DB.closeConn(); 56 | } 57 | } 58 | } 59 | 60 | /** 61 | * 修改课程信息 62 | */ 63 | public void crsModify(String num, String name, String teacher, String place, String type, String time){ 64 | Database DB = new Database(); 65 | this.cNum = num; 66 | this.cName = name; 67 | this.cTeacher = teacher; 68 | this.cPlace = place; 69 | this.cPoint = type; 70 | this.cRatio = time; 71 | 72 | if(cName == null||cName.equals("")){ 73 | JOptionPane.showMessageDialog(null, "请输入课程名称", "错误", JOptionPane.ERROR_MESSAGE); 74 | return; 75 | } 76 | else{ 77 | sql = "update course set cname = '"+cName+"', cTeacher = '"+cTeacher+"', cPlace = '"+cPlace+"', cpoint = '"+cPoint+"', cratio = '"+cRatio+"' where cnum = '"+cNum+"'"; 78 | try{ 79 | DB.OpenConn(); 80 | DB.executeUpdate(sql); 81 | JOptionPane.showMessageDialog(null,"成功修改一条新的纪录!"); 82 | } 83 | catch(Exception e){ 84 | System.out.println(e); 85 | JOptionPane.showMessageDialog(null, "更新失败", "错误", JOptionPane.ERROR_MESSAGE); 86 | } 87 | finally { 88 | DB.closeStmt(); 89 | DB.closeConn(); 90 | } 91 | } 92 | } 93 | 94 | /** 95 | * 删除课程信息 96 | */ 97 | public void crsDel(String num){ 98 | Database DB = new Database(); 99 | this.cNum = num; 100 | 101 | sql = "delete from course where cnum = '"+cNum+"'"; 102 | try{ 103 | DB.OpenConn(); 104 | DB.executeUpdate(sql); 105 | JOptionPane.showMessageDialog(null,"成功删除一条新的纪录!"); 106 | } 107 | catch(Exception e){ 108 | System.out.println(e); 109 | e.printStackTrace(); 110 | JOptionPane.showMessageDialog(null, "删除失败", "错误", JOptionPane.ERROR_MESSAGE); 111 | } 112 | finally { 113 | DB.closeStmt(); 114 | DB.closeConn(); 115 | } 116 | } 117 | 118 | /** 119 | * 根据课程号,搜索课程名称等相关信息 120 | */ 121 | public String[] crsSearch(String num){ 122 | Database DB = new Database(); 123 | this.cNum = num; 124 | String[] s = new String[5]; 125 | 126 | sql = "select * from course where cnum = '"+cNum+"'"; 127 | try{ 128 | DB.OpenConn(); 129 | rs = DB.executeQuery(sql); 130 | if(rs.next()){ 131 | s[0] = rs.getString("cname"); 132 | s[1] = rs.getString("cteacher"); 133 | s[2] = rs.getString("cplace"); 134 | s[3] = rs.getString("cpoint"); 135 | s[4] = rs.getString("cratio"); 136 | } 137 | else 138 | s = null; 139 | } 140 | catch(Exception e){ 141 | } 142 | finally { 143 | DB.closeStmt(); 144 | DB.closeConn(); 145 | } 146 | return s; 147 | } 148 | 149 | /** 150 | * 根据课程名称,搜索课程号 151 | */ 152 | public String[] crsNameSear(String name){ 153 | Database DB = new Database(); 154 | String[] s = new String[6]; 155 | this.cName = name; 156 | //DB.toGBK(cName); 157 | 158 | sql = "select * from course where cname = '"+cName+"'"; 159 | try{ 160 | DB.OpenConn(); 161 | rs = DB.executeQuery(sql); 162 | if(rs.next()){ 163 | s[0] = rs.getString("cname"); 164 | s[1] = rs.getString("cteacher"); 165 | s[2] = rs.getString("cplace"); 166 | s[3] = rs.getString("cpoint"); 167 | s[4] = rs.getString("cratio"); 168 | s[5] = rs.getString("cnum"); 169 | } 170 | else 171 | s = null; 172 | } 173 | catch(Exception e){ 174 | System.out.println(e); 175 | } 176 | finally { 177 | DB.closeStmt(); 178 | DB.closeConn(); 179 | } 180 | return s; 181 | } 182 | 183 | 184 | /** 185 | * 根据课程名称与选课人,搜索课程相关信息 186 | */ 187 | public String[] crsNameSearch(String name,String snum){ 188 | 189 | Database DB = new Database(); 190 | 191 | this.cName = name; 192 | this.sNum = snum; 193 | 194 | String[] s = new String[6]; 195 | sql = "select * from course,sc where cname = '"+cName+"' and sc.snum = '"+sNum+"' and course.cnum = sc.cnum"; 196 | try{ 197 | DB.OpenConn(); 198 | rs = DB.executeQuery(sql); 199 | if(rs.next()){ 200 | s[0] = rs.getString("cnum"); 201 | s[1] = rs.getString("cteacher"); 202 | s[2] = rs.getString("cplace"); 203 | s[3] = rs.getString("cpoint"); 204 | s[4] = rs.getString("cratio"); 205 | s[5] = rs.getString("grade"); 206 | } 207 | else 208 | s = null; 209 | } 210 | catch(Exception e){ 211 | System.out.println(e); 212 | } 213 | finally { 214 | DB.closeStmt(); 215 | DB.closeConn(); 216 | } 217 | return s; 218 | } 219 | 220 | 221 | /** 222 | * 课程信息综合查询 223 | */ 224 | public String[][] crsAllSearch(String colname,String colvalue){ 225 | this.colName = colname; 226 | this.colValue = colvalue; 227 | 228 | Database DB = new Database(); 229 | String[][] cn = null; 230 | int row = 0; 231 | int i = 0; 232 | 233 | if(colValue == null||colValue.equals("")){ 234 | sql = "select * from course"; 235 | } 236 | else{ 237 | sql = "select * from course where "+colName+" = '"+colValue+"'"; 238 | } 239 | 240 | try{ 241 | DB.OpenConn(); 242 | rs = DB.executeQuery(sql); 243 | if(rs.last()){ 244 | row = rs.getRow(); 245 | } 246 | if(row == 0){ 247 | cn = null; 248 | } 249 | else{ 250 | cn = new String[row][6]; 251 | rs.first(); 252 | rs.previous(); 253 | while(rs.next()){ 254 | cn[i][0] = rs.getString("cnum"); 255 | cn[i][1] = rs.getString("cname"); 256 | cn[i][2] = rs.getString("cteacher"); 257 | cn[i][3] = rs.getString("cplace"); 258 | cn[i][4] = rs.getString("cpoint"); 259 | cn[i][5] = rs.getString("cratio"); 260 | i++; 261 | } 262 | } 263 | } 264 | catch(Exception e){ 265 | System.out.println(e); 266 | } 267 | finally { 268 | DB.closeStmt(); 269 | DB.closeConn(); 270 | } 271 | return cn; 272 | } 273 | 274 | 275 | /** 276 | * 获得course表中的所有课程号cnum 277 | */ 278 | public String[] getAllId(){ 279 | 280 | String[] s = null; 281 | int row = 0; 282 | int i = 0; 283 | Database DB = new Database(); 284 | 285 | sql = "select cnum from course"; 286 | try{ 287 | DB.OpenConn(); 288 | rs = DB.executeQuery(sql); 289 | if(rs.last()){ 290 | row = rs.getRow(); 291 | } 292 | if(row == 0){ 293 | s = null; 294 | } 295 | else{ 296 | s = new String[row]; 297 | rs.first(); 298 | rs.previous(); 299 | while(rs.next()){ 300 | s[i] = rs.getString(1); 301 | i++; 302 | } 303 | } 304 | } 305 | catch(Exception e){ 306 | System.out.println(e); 307 | } 308 | finally { 309 | DB.closeStmt(); 310 | DB.closeConn(); 311 | } 312 | return s; 313 | } 314 | 315 | /** 316 | * 获得course表中的所有课程名称 317 | */ 318 | public String[] getAllName(){ 319 | String[] s = null; 320 | int row = 0; 321 | int i = 0; 322 | Database DB = new Database(); 323 | 324 | sql = "select cname from course"; 325 | try{ 326 | DB.OpenConn(); 327 | rs = DB.executeQuery(sql); 328 | if(rs.last()){ 329 | row = rs.getRow(); 330 | } 331 | 332 | if(row == 0){ 333 | s = null; 334 | } 335 | else{ 336 | s = new String[row]; 337 | rs.first(); 338 | rs.previous(); 339 | while(rs.next()){ 340 | s[i] = rs.getString(1); 341 | i++; 342 | } 343 | } 344 | } 345 | catch(Exception e){ 346 | System.out.println(e); 347 | } 348 | finally { 349 | DB.closeStmt(); 350 | DB.closeConn(); 351 | } 352 | return s; 353 | } 354 | } 355 | 356 | -------------------------------------------------------------------------------- /src/学生信息管理系统/Database.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.sql.*; 4 | 5 | /** 6 | * 连接数据库的类 7 | */ 8 | public class Database { 9 | 10 | private Statement stmt=null; 11 | ResultSet rs=null; 12 | private Connection conn=null; 13 | String sql; 14 | String strurl="jdbc:mysql://127.0.0.1:3306/studentsys?characterEncoding=utf8&useSSL=true"; 15 | 16 | public Database(){ 17 | } 18 | 19 | /** 20 | * 打开数据库连接 21 | */ 22 | public void OpenConn()throws Exception{ 23 | try{ 24 | Class.forName("com.mysql.jdbc.Driver"); 25 | conn=DriverManager.getConnection(strurl,"root","5201314qaz,./"); 26 | conn.setAutoCommit(false); 27 | } 28 | catch(Exception e){ 29 | System.err.println("OpenConn:"+e.getMessage()); 30 | e.printStackTrace(); 31 | } 32 | } 33 | 34 | /** 35 | * 执行sql语句,返回结果集rs 36 | */ 37 | public ResultSet executeQuery(String sql){ 38 | stmt = null; 39 | rs=null; 40 | 41 | try{ 42 | 43 | stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); 44 | rs=stmt.executeQuery(sql); 45 | } 46 | catch(SQLException e){ 47 | System.err.println("executeQuery:"+e.getMessage()); 48 | e.printStackTrace(); 49 | } 50 | return rs; 51 | 52 | } 53 | 54 | /** 55 | * 执行sql语句 56 | */ 57 | public int executeUpdate(String sql){ 58 | stmt=null; 59 | rs=null; 60 | int k=0; 61 | try{ 62 | stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); 63 | k=stmt.executeUpdate(sql); 64 | conn.commit(); 65 | } 66 | catch(SQLException e){ 67 | System.err.println("executeUpdate:"+e.getMessage()); 68 | e.printStackTrace(); 69 | } 70 | return k; 71 | } 72 | 73 | public void closeStmt(){ 74 | try{ 75 | stmt.close(); 76 | } 77 | catch(SQLException e){ 78 | System.err.println("closeStmt:"+e.getMessage()); 79 | } 80 | } 81 | 82 | /** 83 | * 关闭数据库连接 84 | */ 85 | public void closeConn(){ 86 | try{ 87 | conn.close(); 88 | } 89 | catch(SQLException ex){ 90 | System.err.println("aq.closeConn:"+ex.getMessage()); 91 | } 92 | } 93 | 94 | 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/学生信息管理系统/DelCourseInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 课程信息管理模块 9 | * 修改课程信息的类 10 | */ 11 | public class DelCourseInfo extends CourseInfo{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | String cNum_str = ""; 17 | public DelCourseInfo() { 18 | this.setTitle("删除课程信息"); 19 | this.setResizable(false); 20 | 21 | cNum.setEditable(false); 22 | cNum.setText("请查询课程号"); 23 | cName.setEditable(false); 24 | cTeacher.setEditable(false); 25 | cPoint.setEditable(false); 26 | cRatio.setEditable(false); 27 | cPlace.setEditable(false); 28 | 29 | //设置运行位置,使对话框居中 30 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 31 | this.setLocation( (int) (screenSize.width - 400) / 2 , 32 | (int) (screenSize.height - 300) / 2 +45); 33 | } 34 | 35 | public void downInit(){ 36 | searchInfo.setText("查询"); 37 | searchInfo.setFont(new Font("Dialog",0,12)); 38 | downPanel.add(searchInfo); 39 | deleteInfo.setText("删除"); 40 | deleteInfo.setFont(new Font("Dialog",0,12)); 41 | downPanel.add(deleteInfo); 42 | clearInfo.setText("清空"); 43 | clearInfo.setFont(new Font("Dialog",0,12)); 44 | downPanel.add(clearInfo); 45 | eixtInfo.setText("退出"); 46 | eixtInfo.setFont(new Font("Dialog",0,12)); 47 | downPanel.add(eixtInfo); 48 | 49 | contentPane.add(downPanel,BorderLayout.SOUTH); 50 | 51 | searchInfo.setEnabled(true); 52 | deleteInfo.setEnabled(false); 53 | eixtInfo.setEnabled(true); 54 | 55 | //添加事件侦听 56 | searchInfo.addActionListener(this); 57 | deleteInfo.addActionListener(this); 58 | eixtInfo.addActionListener(this); 59 | } 60 | /** 61 | * 事件处理 62 | */ 63 | public void actionPerformed(ActionEvent e) { 64 | Object obj = e.getSource(); 65 | String[] s = new String[5]; 66 | 67 | if (obj == eixtInfo) { //退出 68 | this.dispose(); 69 | } 70 | else if (obj == deleteInfo) { //删除 71 | int ifdel = JOptionPane.showConfirmDialog(null,"真的要删除该信息?","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE ); 72 | if(ifdel == JOptionPane.YES_OPTION){ 73 | CrsBean delCrs = new CrsBean(); 74 | delCrs.crsDel(cNum.getText()); 75 | 76 | this.dispose(); 77 | 78 | DelCourseInfo dci = new DelCourseInfo(); 79 | dci.downInit(); 80 | dci.pack(); 81 | dci.setVisible(true); 82 | } 83 | else{ 84 | return; 85 | } 86 | } 87 | else if (obj == searchInfo) { //学号查询 88 | CourseInfoSearchCnum cisc = new CourseInfoSearchCnum(this); 89 | cisc.pack(); 90 | cisc.setVisible(true); 91 | cNum_str = cisc.getCnum(); 92 | 93 | CrsBean searchCrs = new CrsBean(); 94 | s = searchCrs.crsSearch(cNum_str); 95 | if(s == null){ 96 | JOptionPane.showMessageDialog(null, "记录不存在!"); 97 | cNum.setText("请查询学号"); 98 | cName.setText(""); 99 | cTeacher.setText(""); 100 | cPlace.setText(""); 101 | cPoint.setText(""); 102 | cRatio.setText(""); 103 | 104 | cName.setEditable(false); 105 | cTeacher.setEditable(false); 106 | cPlace.setEditable(false); 107 | cPoint.setEditable(false); 108 | cRatio.setEditable(false); 109 | deleteInfo.setEnabled(false); 110 | return; 111 | } 112 | else{ 113 | cNum.setText(cNum_str); 114 | cName.setText(s[0]); 115 | cTeacher.setText(s[1]); 116 | cPlace.setText(s[2]); 117 | cPoint.setText(s[3]); 118 | cRatio.setText(s[4]); 119 | 120 | cName.setEditable(true); 121 | cTeacher.setEditable(true); 122 | cPlace.setEditable(true); 123 | cPoint.setEditable(true); 124 | cRatio.setEditable(true); 125 | deleteInfo.setEnabled(true); 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/学生信息管理系统/DelGradeInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 成绩信息管理模块 9 | * 删除成绩信息的类 10 | */ 11 | public class DelGradeInfo extends GradeInfo implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | 17 | public DelGradeInfo() { 18 | this.setTitle("删除成绩信息"); 19 | this.setResizable(false); 20 | 21 | //设置运行位置,使对话框居中 22 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 23 | this.setLocation( (int) (screenSize.width - 400) / 2 , 24 | (int) (screenSize.height - 300) / 2 +45); 25 | } 26 | 27 | public void downInit(){ 28 | delInfo.setText("删除"); 29 | delInfo.setFont(new Font("Dialog",0,12)); 30 | downPanel.add(delInfo); 31 | eixtInfo.setText("退出"); 32 | eixtInfo.setFont(new Font("Dialog",0,12)); 33 | downPanel.add(eixtInfo); 34 | 35 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 36 | 37 | sNum.addActionListener(this); 38 | delInfo.addActionListener(this); 39 | clearInfo.addActionListener(this); 40 | eixtInfo.addActionListener(this); 41 | } 42 | 43 | /** 44 | * 事件处理 45 | */ 46 | public void actionPerformed(ActionEvent e) { 47 | Object obj = e.getSource(); 48 | 49 | if (obj == delInfo) { //修改 50 | cNum.setEnabled(false); 51 | cName.setEditable(false); 52 | cTeacher.setEditable(false); 53 | Grade.setEditable(false); 54 | sNum.setEditable(false); 55 | sName.setEditable(false); 56 | 57 | delInfo.setEnabled(false); 58 | clearInfo.setEnabled(false); 59 | eixtInfo.setEnabled(false); 60 | 61 | csBean del = new csBean(); 62 | del.csdel(cNum.getText(),(String)sNum.getSelectedItem()); 63 | 64 | this.dispose(); 65 | DelGradeInfo egi = new DelGradeInfo(); 66 | egi.downInit(); 67 | egi.pack(); 68 | egi.setVisible(true); 69 | } 70 | else if (obj == eixtInfo) { //退出 71 | this.dispose(); 72 | } 73 | else if (obj == sNum) { //选择学号 74 | StuBean sN = new StuBean(); 75 | sName.setText(sN.stuSearch((String)sNum.getSelectedItem())[0]); 76 | 77 | if(cName.getItemCount()>0){ 78 | cName.removeAllItems(); 79 | } 80 | 81 | csBean cN = new csBean(); 82 | cReturn = cN.cNameSearch((String)sNum.getSelectedItem()); 83 | 84 | if(cReturn == null){ 85 | cName.removeActionListener(this); 86 | JOptionPane.showMessageDialog(null,"该学生没有选择课程!"); 87 | delInfo.setEnabled(false); 88 | cName.setEnabled(false); 89 | } 90 | else{ 91 | int i = 0; 92 | for(i = 0; i < (cReturn.length); i++){ 93 | cName.addItem(cReturn[i]); 94 | } 95 | 96 | cName.setEnabled(true); 97 | sNum.setEnabled(false); 98 | cName.setSelectedItem(null); 99 | cName.addActionListener(this); 100 | } 101 | } 102 | else if (obj == cName) { //选择课程号 103 | CrsBean cSname = new CrsBean(); 104 | cNum.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[0]); 105 | cTeacher.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[1]); 106 | Grade.setText(""); 107 | Grade.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[5]); 108 | delInfo.setEnabled(true); 109 | 110 | cName.setEnabled(false); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/学生信息管理系统/DelStuInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 学生信息管理模块 9 | * 删除学生信息的类 10 | */ 11 | public class DelStuInfo extends StuInfo{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | String sNum_str = ""; 17 | 18 | public DelStuInfo() { 19 | this.setTitle("删除学生信息"); 20 | this.setResizable(false); 21 | 22 | sNum.setEditable(false); 23 | sNum.setText("请查询学号"); 24 | sName.setEditable(false); 25 | sSex.setEditable(false); 26 | sSethnic.setEditable(false); 27 | sBirth.setEditable(false); 28 | sYear.setEditable(false); 29 | sMajor.setEditable(false); 30 | sCollege.setEditable(false); 31 | sHome.setEditable(false); 32 | 33 | //设置运行时窗口的位置 34 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 35 | this.setLocation((screenSize.width - 400) / 2, 36 | (screenSize.height - 300) / 2 + 45); 37 | } 38 | 39 | public void downInit(){ 40 | searchInfo.setText("学号查询"); 41 | searchInfo.setFont(new Font("Dialog",0,12)); 42 | downPanel.add(searchInfo); 43 | deleteInfo.setText("删除"); 44 | deleteInfo.setFont(new Font("Dialog",0,12)); 45 | downPanel.add(deleteInfo); 46 | eixtInfo.setText("退出"); 47 | eixtInfo.setFont(new Font("Dialog",0,12)); 48 | downPanel.add(eixtInfo); 49 | 50 | searchInfo.setEnabled(true); 51 | deleteInfo.setEnabled(false); 52 | eixtInfo.setEnabled(true); 53 | 54 | //添加事件侦听 55 | searchInfo.addActionListener(this); 56 | deleteInfo.addActionListener(this); 57 | eixtInfo.addActionListener(this); 58 | 59 | contentPane.add(downPanel,BorderLayout.SOUTH); 60 | } 61 | 62 | /** 63 | * 事件处理 64 | */ 65 | public void actionPerformed(ActionEvent e) { 66 | Object obj = e.getSource(); 67 | String[] s = new String[8]; 68 | 69 | if (obj == eixtInfo) { //退出 70 | this.dispose(); 71 | } 72 | else if (obj == deleteInfo) { //删除 73 | int ifdel = JOptionPane.showConfirmDialog(null,"真的要删除该信息?","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE ); 74 | if(ifdel == JOptionPane.YES_OPTION){ 75 | StuBean delStu = new StuBean(); 76 | delStu.stuDel(sNum.getText()); 77 | 78 | this.dispose(); 79 | 80 | DelStuInfo dsi = new DelStuInfo(); 81 | dsi.downInit(); 82 | dsi.pack(); 83 | dsi.setVisible(true); 84 | } 85 | else{ 86 | return; 87 | } 88 | } 89 | else if (obj == searchInfo) { //学号查询 90 | StuInfoSearchSnum siss = new StuInfoSearchSnum(this); 91 | siss.pack(); 92 | siss.setVisible(true); 93 | sNum_str = siss.getSnum(); 94 | StuBean searchStu = new StuBean(); 95 | s = searchStu.stuSearch(sNum_str); 96 | 97 | if(s == null){ 98 | JOptionPane.showMessageDialog(null, "记录不存在!"); 99 | sNum.setText("请查询学号"); 100 | sName.setText(""); 101 | sSex.setText(""); 102 | sSethnic.setText(""); 103 | sHome.setText(""); 104 | sYear.setText(""); 105 | sMajor.setText(""); 106 | sCollege.setText(""); 107 | sBirth.setText(""); 108 | deleteInfo.setEnabled(false); 109 | return; 110 | } 111 | else{ 112 | sNum.setText(sNum_str); 113 | sName.setText(s[0]); 114 | sSex.setText(s[1]); 115 | sSethnic.setText(s[2]); 116 | sHome.setText(s[3]); 117 | sYear.setText(s[4]); 118 | sMajor.setText(s[5]); 119 | sCollege.setText(s[6]); 120 | sBirth.setText(s[7]); 121 | deleteInfo.setEnabled(true); 122 | } 123 | 124 | } 125 | } 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/学生信息管理系统/EditCourseInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | import javax.swing.*; 7 | 8 | public class EditCourseInfo extends CourseInfo { 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 1L; 13 | String cNum_str = ""; 14 | public EditCourseInfo() { 15 | this.setTitle("修改课程信息"); 16 | this.setResizable(false); 17 | 18 | cNum.setEditable(false); 19 | cNum.setText("请查询课程号"); 20 | cName.setEditable(false); 21 | cTeacher.setEditable(false); 22 | cPoint.setEditable(false); 23 | cRatio.setEditable(false); 24 | cPlace.setEditable(false); 25 | 26 | //设置运行位置,使对话框居中 27 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 28 | this.setLocation( (int) (screenSize.width - 400) / 2 , 29 | (int) (screenSize.height - 300) / 2 +45); 30 | } 31 | 32 | public void downInit(){ 33 | searchInfo.setText("查询"); 34 | searchInfo.setFont(new Font("Dialog",0,12)); 35 | downPanel.add(searchInfo); 36 | modifyInfo.setText("修改"); 37 | modifyInfo.setFont(new Font("Dialog",0,12)); 38 | downPanel.add(modifyInfo); 39 | clearInfo.setText("清空"); 40 | clearInfo.setFont(new Font("Dialog",0,12)); 41 | downPanel.add(clearInfo); 42 | eixtInfo.setText("退出"); 43 | eixtInfo.setFont(new Font("Dialog",0,12)); 44 | downPanel.add(eixtInfo); 45 | 46 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 47 | 48 | searchInfo.setEnabled(true); 49 | modifyInfo.setEnabled(false); 50 | clearInfo.setEnabled(true); 51 | eixtInfo.setEnabled(true); 52 | 53 | //添加事件侦听 54 | searchInfo.addActionListener(this); 55 | modifyInfo.addActionListener(this); 56 | clearInfo.addActionListener(this); 57 | eixtInfo.addActionListener(this); 58 | } 59 | 60 | /** 61 | * 事件处理 62 | */ 63 | public void actionPerformed(ActionEvent e) { 64 | Object obj = e.getSource(); 65 | String[] s = new String[5]; 66 | 67 | if (obj == eixtInfo) { //退出 68 | this.dispose(); 69 | } 70 | else if (obj == modifyInfo) { //修改 71 | CrsBean modifyCrs = new CrsBean(); 72 | modifyCrs.crsModify(cNum.getText(), cName.getText(), cTeacher.getText(), cPlace.getText(), cPoint.getText(), cRatio.getText()); 73 | modifyCrs.crsSearch(cNum.getText()); 74 | s = modifyCrs.crsSearch(cNum_str); 75 | 76 | cName.setText(s[0]); 77 | cTeacher.setText(s[1]); 78 | cPlace.setText(s[2]); 79 | cPoint.setText(s[3]); 80 | cRatio.setText(s[4]); 81 | 82 | } 83 | else if (obj == clearInfo) { //清空 84 | setNull(); 85 | cNum.setText("请查询课程号"); 86 | } 87 | else if (obj == searchInfo) { //课程号查询 88 | CourseInfoSearchCnum cisc = new CourseInfoSearchCnum(this); 89 | cisc.pack(); 90 | cisc.setVisible(true); 91 | cNum_str = cisc.getCnum(); 92 | 93 | CrsBean searchCrs = new CrsBean(); 94 | s = searchCrs.crsSearch(cNum_str); 95 | if(s == null){ 96 | JOptionPane.showMessageDialog(null, "记录不存在!"); 97 | cNum.setText("请查询学号"); 98 | cName.setText(""); 99 | cTeacher.setText(""); 100 | cPlace.setText(""); 101 | cPoint.setText(""); 102 | cRatio.setText(""); 103 | 104 | cName.setEditable(false); 105 | cTeacher.setEditable(false); 106 | cPlace.setEditable(false); 107 | cPoint.setEditable(false); 108 | cRatio.setEditable(false); 109 | modifyInfo.setEnabled(false); 110 | return; 111 | } 112 | else{ 113 | cNum.setText(cNum_str); 114 | cName.setText(s[0]); 115 | cTeacher.setText(s[1]); 116 | cPlace.setText(s[2]); 117 | cPoint.setText(s[3]); 118 | cRatio.setText(s[4]); 119 | 120 | 121 | cName.setEditable(true); 122 | cTeacher.setEditable(true); 123 | cPlace.setEditable(true); 124 | cPoint.setEditable(true); 125 | cRatio.setEditable(true); 126 | modifyInfo.setEnabled(true); 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/学生信息管理系统/EditGradeInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 成绩信息管理模块 9 | * 修改成绩信息的类 10 | */ 11 | public class EditGradeInfo extends GradeInfo implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | 17 | public EditGradeInfo() { 18 | this.setTitle("修改成绩信息"); 19 | this.setResizable(false); 20 | 21 | //设置运行位置,使对话框居中 22 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 23 | this.setLocation( (int) (screenSize.width - 400) / 2 , 24 | (int) (screenSize.height - 300) / 2 +45); 25 | } 26 | 27 | public void downInit(){ 28 | modifyInfo.setText("修改"); 29 | modifyInfo.setFont(new Font("Dialog",0,12)); 30 | downPanel.add(modifyInfo); 31 | eixtInfo.setText("退出"); 32 | eixtInfo.setFont(new Font("Dialog",0,12)); 33 | downPanel.add(eixtInfo); 34 | 35 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 36 | 37 | sNum.addActionListener(this); 38 | modifyInfo.addActionListener(this); 39 | clearInfo.addActionListener(this); 40 | eixtInfo.addActionListener(this); 41 | } 42 | 43 | /** 44 | * 事件处理 45 | */ 46 | public void actionPerformed(ActionEvent e) { 47 | Object obj = e.getSource(); 48 | 49 | if (obj == modifyInfo) { //修改 50 | cNum.setEnabled(false); 51 | cName.setEditable(false); 52 | cTeacher.setEditable(false); 53 | Grade.setEditable(false); 54 | sNum.setEditable(false); 55 | sName.setEditable(false); 56 | 57 | modifyInfo.setEnabled(false); 58 | clearInfo.setEnabled(false); 59 | eixtInfo.setEnabled(false); 60 | 61 | csBean addGrade = new csBean(); 62 | addGrade.csModify(cNum.getText(),(String)sNum.getSelectedItem(),Grade.getText()); 63 | 64 | this.dispose(); 65 | EditGradeInfo egi = new EditGradeInfo(); 66 | egi.downInit(); 67 | egi.pack(); 68 | egi.setVisible(true); 69 | } 70 | else if (obj == eixtInfo) { //退出 71 | this.dispose(); 72 | } 73 | else if (obj == sNum) { //选择学号 74 | StuBean sN = new StuBean(); 75 | sName.setText(sN.stuSearch((String)sNum.getSelectedItem())[0]); 76 | 77 | if(cName.getItemCount()>0){ 78 | cName.removeAllItems(); 79 | } 80 | 81 | csBean cN = new csBean(); 82 | cReturn = cN.cNameSearch((String)sNum.getSelectedItem()); 83 | 84 | if(cReturn == null){ 85 | cName.removeActionListener(this); 86 | JOptionPane.showMessageDialog(null,"该学生没有选择课程!"); 87 | modifyInfo.setEnabled(false); 88 | cName.setEnabled(false); 89 | } 90 | else{ 91 | int i = 0; 92 | for(i = 0; i < (cReturn.length); i++){ 93 | cName.addItem(cReturn[i]); 94 | } 95 | 96 | cName.setEnabled(true); 97 | sNum.setEnabled(false); 98 | cName.setSelectedItem(null); 99 | cName.addActionListener(this); 100 | } 101 | } 102 | else if (obj == cName) { //选择课程号 103 | CrsBean cSname = new CrsBean(); 104 | cNum.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[0]); 105 | cTeacher.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[1]); 106 | Grade.setText(""); 107 | Grade.setText(cSname.crsNameSearch((String)cName.getSelectedItem(),(String)sNum.getSelectedItem())[5]); 108 | modifyInfo.setEnabled(true); 109 | 110 | cName.setEnabled(false); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/学生信息管理系统/EditStuInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 学生信息管理模块 9 | * 修改学生信息的类 10 | */ 11 | public class EditStuInfo extends StuInfo { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | String sNum_str = ""; 17 | public EditStuInfo() { 18 | this.setTitle("修改学生信息"); 19 | this.setResizable(false); 20 | 21 | sNum.setEditable(false); 22 | sNum.setText("请查询学号"); 23 | sName.setEditable(false); 24 | sSex.setEditable(false); 25 | sSethnic.setEditable(false); 26 | sBirth.setEditable(false); 27 | sYear.setEditable(false); 28 | sMajor.setEditable(false); 29 | sCollege.setEditable(false); 30 | sHome.setEditable(false); 31 | 32 | //设置运行时窗口的位置 33 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 34 | this.setLocation((screenSize.width - 400) / 2, 35 | (screenSize.height - 300) / 2 + 45); 36 | } 37 | 38 | public void downInit(){ 39 | searchInfo.setText("学号查询"); 40 | searchInfo.setFont(new Font("Dialog",0,12)); 41 | downPanel.add(searchInfo); 42 | modifyInfo.setText("修改"); 43 | modifyInfo.setFont(new Font("Dialog",0,12)); 44 | downPanel.add(modifyInfo); 45 | clearInfo.setText("清空"); 46 | clearInfo.setFont(new Font("Dialog",0,12)); 47 | downPanel.add(clearInfo); 48 | eixtInfo.setText("退出"); 49 | eixtInfo.setFont(new Font("Dialog",0,12)); 50 | downPanel.add(eixtInfo); 51 | 52 | searchInfo.setEnabled(true); 53 | modifyInfo.setEnabled(false); 54 | clearInfo.setEnabled(true); 55 | eixtInfo.setEnabled(true); 56 | 57 | //添加事件侦听 58 | searchInfo.addActionListener(this); 59 | modifyInfo.addActionListener(this); 60 | clearInfo.addActionListener(this); 61 | eixtInfo.addActionListener(this); 62 | 63 | this.contentPane.add(downPanel,BorderLayout.SOUTH); 64 | } 65 | 66 | /** 67 | * 事件处理 68 | */ 69 | public void actionPerformed(ActionEvent e) { 70 | Object obj = e.getSource(); 71 | String[] s = new String[8]; 72 | 73 | if (obj == eixtInfo) { //退出 74 | this.dispose(); 75 | } 76 | else if (obj == modifyInfo) { //修改 77 | StuBean modifyStu = new StuBean(); 78 | modifyStu.stuModify(sNum.getText(), sName.getText(), sSex.getText(), sBirth.getText(), sHome.getText(), sSethnic.getText(), sYear.getText(), sMajor.getText(), sCollege.getText()); 79 | modifyStu.stuSearch(sNum.getText()); 80 | s = modifyStu.stuSearch(sNum_str); 81 | 82 | sName.setText(s[0]); 83 | sSex.setText(s[1]); 84 | sSethnic.setText(s[2]); 85 | sHome.setText(s[3]); 86 | sYear.setText(s[4]); 87 | sMajor.setText(s[5]); 88 | sCollege.setText(s[6]); 89 | sBirth.setText(s[7]); 90 | } 91 | else if (obj == clearInfo) { //清空 92 | setNull(); 93 | sNum.setText("请查询学号"); 94 | } 95 | else if (obj == searchInfo) { //学号查询 96 | 97 | StuInfoSearchSnum siss = new StuInfoSearchSnum(this); 98 | siss.pack(); 99 | siss.setVisible(true); 100 | try{ 101 | sNum_str = siss.getSnum(); 102 | }catch(Exception ex){ 103 | JOptionPane.showMessageDialog(null, "没有查找到该学号!"); 104 | } 105 | 106 | StuBean searchStu = new StuBean(); 107 | s = searchStu.stuSearch(sNum_str); 108 | if(s == null){ 109 | JOptionPane.showMessageDialog(null, "记录不存在!"); 110 | sNum.setText("请查询学号"); 111 | sName.setText(""); 112 | sSex.setText(""); 113 | sSethnic.setText(""); 114 | sHome.setText(""); 115 | sYear.setText(""); 116 | sMajor.setText(""); 117 | sCollege.setText(""); 118 | sBirth.setText(""); 119 | 120 | sName.setEditable(false); 121 | sSex.setEditable(false); 122 | sSethnic.setEditable(false); 123 | sBirth.setEditable(false); 124 | sYear.setEditable(false); 125 | sMajor.setEditable(false); 126 | sCollege.setEditable(false); 127 | sHome.setEditable(false); 128 | modifyInfo.setEnabled(false); 129 | return; 130 | } 131 | else{ 132 | sNum.setText(sNum_str); 133 | sName.setText(s[0]); 134 | sSex.setText(s[1]); 135 | sSethnic.setText(s[2]); 136 | sHome.setText(s[3]); 137 | sYear.setText(s[4]); 138 | sMajor.setText(s[5]); 139 | sCollege.setText(s[6]); 140 | sBirth.setText(s[7]); 141 | 142 | sName.setEditable(true); 143 | sSex.setEditable(true); 144 | sSethnic.setEditable(true); 145 | sBirth.setEditable(true); 146 | sYear.setEditable(true); 147 | sMajor.setEditable(true); 148 | sCollege.setEditable(true); 149 | sHome.setEditable(true); 150 | modifyInfo.setEnabled(true); 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/学生信息管理系统/GradeInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | /** 7 | * 成绩信息综合管理类 8 | * 提供主界面,供其他类继承 9 | */ 10 | public class GradeInfo extends JFrame{ 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | Container contentPane; 16 | JPanel centerPanel = new JPanel(); 17 | JPanel upPanel = new JPanel(); 18 | JPanel downPanel = new JPanel(); 19 | 20 | //框架的大小 21 | Dimension faceSize = new Dimension(800, 500); 22 | 23 | JLabel jLabel1 = new JLabel(); 24 | JLabel jLabel2 = new JLabel(); 25 | JLabel jLabel3 = new JLabel(); 26 | JLabel jLabel4 = new JLabel(); 27 | JLabel jLabel5 = new JLabel(); 28 | JLabel jLabel6 = new JLabel(); 29 | 30 | String[] stu = null;//记录所有的学号 31 | String[] cReturn = null;//记录学生的选课信息 32 | 33 | JComboBox sNum; 34 | JTextField sName = new JTextField(15); 35 | JTextField cNum = new JTextField(15); 36 | JComboBox cName; 37 | JTextField cTeacher = new JTextField(15); 38 | JTextField Grade = new JTextField(15); 39 | JTextField sMajor = new JTextField(15); 40 | JTextField sCollege = new JTextField(15); 41 | JTextField sHome = new JTextField(46); 42 | JButton searchInfo = new JButton(); 43 | JButton addInfo = new JButton(); 44 | JButton modifyInfo = new JButton(); 45 | JButton delInfo = new JButton(); 46 | JButton deleteInfo = new JButton(); 47 | JButton clearInfo = new JButton(); 48 | JButton saveInfo = new JButton(); 49 | JButton eixtInfo = new JButton(); 50 | 51 | GridBagLayout girdBag = new GridBagLayout(); 52 | GridBagConstraints girdBagCon; 53 | 54 | public GradeInfo() { 55 | this.setSize(faceSize); 56 | this.setResizable(false); 57 | //设置标题 58 | //this.setTitle("成绩综合信息管理"); 59 | 60 | 61 | try { 62 | Init(); 63 | } 64 | catch(Exception e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | public void Init() throws Exception { 70 | contentPane = this.getContentPane(); 71 | contentPane.setLayout(new BorderLayout()); 72 | 73 | //中部面板的布局 74 | centerPanel.setLayout(girdBag); 75 | 76 | jLabel1.setText("学 号:"); 77 | jLabel1.setFont(new Font("Dialog",0,12)); 78 | girdBagCon = new GridBagConstraints(); 79 | girdBagCon.gridx = 0; 80 | girdBagCon.gridy = 0; 81 | girdBagCon.insets = new Insets(10,10,10,1); 82 | girdBag.setConstraints(jLabel1,girdBagCon); 83 | centerPanel.add(jLabel1); 84 | 85 | StuBean sN = new StuBean(); 86 | stu = sN.getAllId(); 87 | sNum = new JComboBox(stu); 88 | girdBagCon = new GridBagConstraints(); 89 | girdBagCon.gridx = 1; 90 | girdBagCon.gridy = 0; 91 | girdBagCon.fill = girdBagCon.BOTH; 92 | girdBagCon.insets = new Insets(10,1,10,15); 93 | sNum.setSelectedItem(null); 94 | girdBag.setConstraints(sNum,girdBagCon); 95 | centerPanel.add(sNum); 96 | 97 | jLabel2.setText("姓 名:"); 98 | jLabel2.setFont(new Font("Dialog",0,12)); 99 | girdBagCon = new GridBagConstraints(); 100 | girdBagCon.gridx = 2; 101 | girdBagCon.gridy = 0; 102 | girdBagCon.insets = new Insets(10,15,10,1); 103 | girdBag.setConstraints(jLabel2,girdBagCon); 104 | centerPanel.add(jLabel2); 105 | 106 | girdBagCon = new GridBagConstraints(); 107 | girdBagCon.gridx = 3; 108 | girdBagCon.gridy = 0; 109 | girdBagCon.insets = new Insets(10,1,10,10); 110 | sName.setEnabled(false); 111 | girdBag.setConstraints(sName,girdBagCon); 112 | centerPanel.add(sName); 113 | 114 | jLabel3.setText("课程名称:"); 115 | jLabel3.setFont(new Font("Dialog",0,12)); 116 | girdBagCon = new GridBagConstraints(); 117 | girdBagCon.gridx = 0; 118 | girdBagCon.gridy = 1; 119 | girdBagCon.insets = new Insets(10,10,10,1); 120 | girdBag.setConstraints(jLabel3,girdBagCon); 121 | centerPanel.add(jLabel3); 122 | 123 | cName = new JComboBox(); 124 | girdBagCon = new GridBagConstraints(); 125 | girdBagCon.gridx = 1; 126 | girdBagCon.gridy = 1; 127 | girdBagCon.fill = girdBagCon.BOTH; 128 | girdBagCon.insets = new Insets(10,1,10,15); 129 | girdBag.setConstraints(cName,girdBagCon); 130 | centerPanel.add(cName); 131 | 132 | jLabel4.setText("课程编码:"); 133 | jLabel4.setFont(new Font("Dialog",0,12)); 134 | girdBagCon = new GridBagConstraints(); 135 | girdBagCon.gridx = 2; 136 | girdBagCon.gridy = 1; 137 | girdBagCon.insets = new Insets(10,15,10,1); 138 | girdBag.setConstraints(jLabel4,girdBagCon); 139 | centerPanel.add(jLabel4); 140 | 141 | girdBagCon = new GridBagConstraints(); 142 | girdBagCon.gridx = 3; 143 | girdBagCon.gridy = 1; 144 | girdBagCon.insets = new Insets(10,1,10,10); 145 | cNum.setEditable(false); 146 | girdBag.setConstraints(cNum,girdBagCon); 147 | centerPanel.add(cNum); 148 | 149 | jLabel5.setText("授课老师:"); 150 | jLabel5.setFont(new Font("Dialog",0,12)); 151 | girdBagCon = new GridBagConstraints(); 152 | girdBagCon.gridx = 0; 153 | girdBagCon.gridy = 2; 154 | girdBagCon.insets = new Insets(10,10,10,1); 155 | girdBag.setConstraints(jLabel5,girdBagCon); 156 | centerPanel.add(jLabel5); 157 | 158 | girdBagCon = new GridBagConstraints(); 159 | girdBagCon.gridx = 1; 160 | girdBagCon.gridy = 2; 161 | girdBagCon.insets = new Insets(10,1,10,15); 162 | cTeacher.setEnabled(false); 163 | girdBag.setConstraints(cTeacher,girdBagCon); 164 | centerPanel.add(cTeacher); 165 | 166 | jLabel6.setText("成 绩:"); 167 | jLabel6.setFont(new Font("Dialog",0,12)); 168 | girdBagCon = new GridBagConstraints(); 169 | girdBagCon.gridx = 2; 170 | girdBagCon.gridy = 2; 171 | girdBagCon.insets = new Insets(10,15,10,1); 172 | girdBag.setConstraints(jLabel6,girdBagCon); 173 | centerPanel.add(jLabel6); 174 | 175 | girdBagCon = new GridBagConstraints(); 176 | girdBagCon.gridx = 3; 177 | girdBagCon.insets = new Insets(10,1,10,10); 178 | girdBag.setConstraints(Grade,girdBagCon); 179 | centerPanel.add(Grade); 180 | 181 | contentPane.add(centerPanel,BorderLayout.CENTER); 182 | } 183 | 184 | /** 185 | * 下部面板的布局 186 | */ 187 | public void downInit(){ 188 | searchInfo.setText("查询"); 189 | searchInfo.setFont(new Font("Dialog",0,12)); 190 | downPanel.add(searchInfo); 191 | addInfo.setText("增加"); 192 | addInfo.setFont(new Font("Dialog",0,12)); 193 | downPanel.add(addInfo); 194 | modifyInfo.setText("修改"); 195 | modifyInfo.setFont(new Font("Dialog",0,12)); 196 | downPanel.add(modifyInfo); 197 | deleteInfo.setText("删除"); 198 | deleteInfo.setFont(new Font("Dialog",0,12)); 199 | downPanel.add(deleteInfo); 200 | saveInfo.setText("保存"); 201 | saveInfo.setFont(new Font("Dialog",0,12)); 202 | downPanel.add(saveInfo); 203 | clearInfo.setText("清空"); 204 | clearInfo.setFont(new Font("Dialog",0,12)); 205 | downPanel.add(clearInfo); 206 | eixtInfo.setText("退出"); 207 | eixtInfo.setFont(new Font("Dialog",0,12)); 208 | downPanel.add(eixtInfo); 209 | 210 | contentPane.add(downPanel,BorderLayout.SOUTH); 211 | } 212 | 213 | 214 | } 215 | -------------------------------------------------------------------------------- /src/学生信息管理系统/GrdSearchAllGrade.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 成绩信息查询模块 9 | * 查询某学生所有科目的成绩 10 | */ 11 | public class GrdSearchAllGrade extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | //框架的大小 18 | Dimension faceSize = new Dimension(300, 100); 19 | String[] stu ; 20 | JLabel jLabel1 = new JLabel(); 21 | JComboBox sNum; 22 | JButton searchInfo = new JButton(); 23 | 24 | public GrdSearchAllGrade() { 25 | //设置标题 26 | this.setTitle("所有成绩查询"); 27 | this.setResizable(false); 28 | 29 | try { 30 | Init(); 31 | } 32 | catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | //设置运行位置,使对话框居中 36 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 37 | this.setLocation( (int) (screenSize.width - 400) / 2 , 38 | (int) (screenSize.height - 300) / 2 + 45); 39 | } 40 | 41 | private void Init() throws Exception { 42 | this.setSize(faceSize); 43 | contentPane = this.getContentPane(); 44 | contentPane.setLayout(new FlowLayout()); 45 | 46 | jLabel1.setText("请选择学号 :"); 47 | jLabel1.setFont(new Font("Dialog",0,12)); 48 | contentPane.add(jLabel1); 49 | 50 | StuBean sN = new StuBean(); 51 | stu = sN.getAllId(); 52 | sNum = new JComboBox(stu); 53 | sNum.setSelectedItem(null); 54 | sNum.setFont(new Font("Dialog",0,12)); 55 | contentPane.add(sNum); 56 | 57 | searchInfo.setText("确定"); 58 | searchInfo.setFont(new Font("Dialog",0,12)); 59 | contentPane.add(searchInfo); 60 | 61 | searchInfo.addActionListener(this); 62 | } 63 | 64 | /** 65 | * 事件处理 66 | */ 67 | public void actionPerformed(ActionEvent e) { 68 | Object obj = e.getSource(); 69 | if (obj == searchInfo) { //查询 70 | ResultGrade rG = new ResultGrade((String)sNum.getSelectedItem()); 71 | this.dispose(); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/学生信息管理系统/Main.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.UIManager; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | //设置运行风格 8 | try { 9 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 10 | } 11 | catch(Exception e) { 12 | e.printStackTrace(); 13 | } 14 | new login(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/学生信息管理系统/ResultCourse.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | import java.awt.*; 3 | import javax.swing.*; 4 | 5 | 6 | /** 7 | * 显示课程查询模块查询结果的类 8 | */ 9 | public class ResultCourse extends JFrame { 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | JLabel jLabel1 = new JLabel(); 15 | JButton jBExit = new JButton(); 16 | JScrollPane jScrollPane1 ; 17 | JTable jTabStuInfo; 18 | String[] colName = {"课程号","课程名称","授课老师","上课地点","课程学分","课程系数"}; 19 | String[][] colValue; 20 | String sColValue; 21 | String sColName; 22 | 23 | public ResultCourse(String colname,String colvalue) { 24 | this.sColValue = colvalue; 25 | this.sColName = colname; 26 | 27 | this.setTitle("课程查询结果"); 28 | 29 | //设置运行位置,使对话框居中 30 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 31 | this.setLocation( (int) (screenSize.width - 200) / 2 , 32 | (int) (screenSize.height - 300) / 2 + 45); 33 | CrsBean rCrs = new CrsBean(); 34 | try { 35 | colValue = rCrs.crsAllSearch(sColName,sColValue); 36 | if(colValue == null){ 37 | JOptionPane.showMessageDialog(null, "没有符合条件的记录"); 38 | this.dispose(); 39 | } 40 | else{ 41 | jTabStuInfo = new JTable(colValue,colName); 42 | jScrollPane1 = new JScrollPane(jTabStuInfo); 43 | this.getContentPane().add(jScrollPane1,BorderLayout.CENTER); 44 | this.pack(); 45 | this.setVisible(true); 46 | } 47 | } 48 | catch(Exception e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/学生信息管理系统/ResultGrade.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import javax.swing.*; 5 | 6 | /** 7 | * 显示成绩查询模块查询结果的类 8 | */ 9 | public class ResultGrade extends JFrame { 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | JLabel jLabel1 = new JLabel(); 15 | JButton jBExit = new JButton(); 16 | JScrollPane jScrollPane1 ; 17 | JTable jTabStuInfo; 18 | 19 | String sNum; 20 | String[] colName = {"学号","姓名","课程号","课程名称","成绩"}; 21 | String[][] colValue; 22 | 23 | public ResultGrade(String sNum) { 24 | this.setTitle("成绩查询结果"); 25 | 26 | //设置运行位置,使对话框居中 27 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 28 | this.setLocation( (int) (screenSize.width - 400) / 2 , 29 | (int) (screenSize.height - 300) / 2 + 45); 30 | 31 | this.sNum = sNum; 32 | csBean rGrade = new csBean(); 33 | try { 34 | colValue = rGrade.csAllSearch(sNum,5); 35 | if(colValue == null){ 36 | JOptionPane.showMessageDialog(null, "没有符合条件的记录"); 37 | this.dispose(); 38 | } 39 | else{ 40 | jTabStuInfo = new JTable(colValue,colName); 41 | jScrollPane1 = new JScrollPane(jTabStuInfo); 42 | this.getContentPane().add(jScrollPane1,BorderLayout.CENTER); 43 | this.pack(); 44 | this.setVisible(true); 45 | } 46 | } 47 | catch(Exception e) { 48 | } 49 | } 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/学生信息管理系统/ResultStudent.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import javax.swing.*; 5 | 6 | /** 7 | * 显示学生查询模块查询结果的类 8 | */ 9 | public class ResultStudent extends JFrame { 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | JLabel jLabel1 = new JLabel(); 15 | JButton jBExit = new JButton(); 16 | JScrollPane jScrollPane1 ; 17 | JTable jTabStuInfo; 18 | 19 | String sNum; 20 | String[] colName = {"学号","姓名","性别","民族","籍贯","入学年份","专业","学院","出生日期"}; 21 | String[][] colValue; 22 | String sColValue; 23 | String sColName; 24 | String sFromValue; 25 | String sToValue; 26 | 27 | String sCourse; 28 | 29 | public ResultStudent(String colname,String colvalue) { 30 | this.sColValue = colvalue; 31 | this.sColName = colname; 32 | 33 | this.setTitle("学生信息查询结果"); 34 | 35 | //设置运行位置,使对话框居中 36 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 37 | this.setLocation( (int) (screenSize.width - 400) / 2 , 38 | (int) (screenSize.height - 300) / 2 + 45); 39 | //this.setSize(500, 500); 40 | StuBean rStu = new StuBean(); 41 | try { 42 | colValue = rStu.stuAllSearch(sColName,sColValue); 43 | if(colValue == null){ 44 | JOptionPane.showMessageDialog(null, "没有符合条件的记录"); 45 | this.dispose(); 46 | } 47 | else{ 48 | jTabStuInfo = new JTable(colValue,colName); 49 | jScrollPane1 = new JScrollPane(jTabStuInfo); 50 | this.getContentPane().add(jScrollPane1,BorderLayout.CENTER); 51 | this.pack(); 52 | this.setVisible(true); 53 | } 54 | } 55 | catch(Exception e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | public ResultStudent(String colname,String fromvalue,String tovalue) { 61 | this.sColName = colname; 62 | this.sFromValue = fromvalue; 63 | this.sToValue = tovalue; 64 | 65 | this.setTitle("学生信息查询结果"); 66 | 67 | //设置运行位置,使对话框居中 68 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 69 | this.setLocation( (int) (screenSize.width - 400) / 2 , 70 | (int) (screenSize.height - 300) / 2 + 45); 71 | StuBean rStu = new StuBean(); 72 | try { 73 | colValue = rStu.stuAllSearch(sColName,sFromValue,sToValue); 74 | if(colValue == null){ 75 | this.dispose(); 76 | JOptionPane.showMessageDialog(null, "没有符合条件的记录"); 77 | } 78 | else{ 79 | jTabStuInfo = new JTable(colValue,colName); 80 | jScrollPane1 = new JScrollPane(jTabStuInfo); 81 | this.getContentPane().add(jScrollPane1,BorderLayout.CENTER); 82 | this.pack(); 83 | this.setVisible(true); 84 | } 85 | } 86 | catch(Exception e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | 91 | 92 | public ResultStudent(String course) { 93 | this.sCourse = course; 94 | 95 | this.setTitle("学生信息查询结果"); 96 | 97 | //设置运行位置,使对话框居 98 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 99 | this.setLocation( (int) (screenSize.width - 400) / 2 , 100 | (int) (screenSize.height - 300) / 2 + 45); 101 | StuBean rStu = new StuBean(); 102 | try { 103 | colValue = rStu.stuSearchBySimple(sCourse); 104 | if(colValue == null){ 105 | JOptionPane.showMessageDialog(null, "没有符合条件的记录"); 106 | this.dispose(); 107 | } 108 | else{ 109 | jTabStuInfo = new JTable(colValue,colName); 110 | jScrollPane1 = new JScrollPane(jTabStuInfo); 111 | this.getContentPane().add(jScrollPane1,BorderLayout.CENTER); 112 | this.pack(); 113 | this.setVisible(true); 114 | } 115 | } 116 | catch(Exception e) { 117 | e.printStackTrace(); 118 | } 119 | } 120 | 121 | public ResultStudent() { 122 | this.setTitle("学生信息查询结果"); 123 | 124 | //设置运行位置,使对话框居中 125 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 126 | this.setLocation( (int) (screenSize.width - 400) / 2 , 127 | (int) (screenSize.height - 300) / 2 + 45); 128 | StuBean rStu = new StuBean(); 129 | try { 130 | colValue = rStu.stuSearchBypoint(); 131 | if(colValue == null){ 132 | JOptionPane.showMessageDialog(null, "没有符合条件的记录"); 133 | this.dispose(); 134 | } 135 | else{ 136 | jTabStuInfo = new JTable(colValue,colName); 137 | jScrollPane1 = new JScrollPane(jTabStuInfo); 138 | this.getContentPane().add(jScrollPane1,BorderLayout.CENTER); 139 | this.pack(); 140 | this.setVisible(true); 141 | } 142 | } 143 | catch(Exception e) { 144 | e.printStackTrace(); 145 | } 146 | } 147 | 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/学生信息管理系统/SelectCourse.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 学生选课的类 9 | */ 10 | public class SelectCourse extends JFrame implements ActionListener{ 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | Container contentPane; 16 | JPanel centerPanel = new JPanel(); 17 | JPanel upPanel = new JPanel(); 18 | JPanel downPanel = new JPanel(); 19 | 20 | //框架的大小 21 | Dimension faceSize = new Dimension(800, 500); 22 | 23 | JLabel jLabel1 = new JLabel(); 24 | JLabel jLabel2 = new JLabel(); 25 | JLabel jLabel3 = new JLabel(); 26 | JLabel jLabel4 = new JLabel(); 27 | JLabel jLabel5 = new JLabel(); 28 | JLabel jLabel6 = new JLabel(); 29 | 30 | String[] s; 31 | JComboBox sNum; 32 | JTextField sName = new JTextField(15); 33 | JTextField cNum = new JTextField(15); 34 | JComboBox cName; 35 | JTextField cTeacher = new JTextField(15); 36 | JTextField Cplace = new JTextField(15); 37 | JTextField sMajor = new JTextField(15); 38 | JTextField sCollege = new JTextField(15); 39 | JTextField sHome = new JTextField(46); 40 | JButton selectCourse = new JButton(); 41 | JButton cancel = new JButton(); 42 | 43 | GridBagLayout girdBag = new GridBagLayout(); 44 | GridBagConstraints girdBagCon; 45 | 46 | public SelectCourse() { 47 | this.setSize(faceSize); 48 | this.setResizable(false); 49 | //设置标题 50 | this.setTitle("学生选课"); 51 | 52 | //设置运行时窗口的位置 53 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 54 | this.setLocation((screenSize.width - 400) / 2, 55 | (screenSize.height - 300) / 2 + 45); 56 | 57 | try { 58 | Init(); 59 | } 60 | catch(Exception e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | public void Init() throws Exception { 66 | contentPane = this.getContentPane(); 67 | contentPane.setLayout(new BorderLayout()); 68 | 69 | //中部面板的布局 70 | centerPanel.setLayout(girdBag); 71 | 72 | jLabel1.setText("学 号:"); 73 | jLabel1.setFont(new Font("Dialog",0,12)); 74 | girdBagCon = new GridBagConstraints(); 75 | girdBagCon.gridx = 0; 76 | girdBagCon.gridy = 0; 77 | girdBagCon.insets = new Insets(10,10,10,1); 78 | girdBag.setConstraints(jLabel1,girdBagCon); 79 | centerPanel.add(jLabel1); 80 | 81 | StuBean sN = new StuBean(); 82 | s = sN.getAllId(); 83 | sNum = new JComboBox(s); 84 | girdBagCon = new GridBagConstraints(); 85 | girdBagCon.gridx = 1; 86 | girdBagCon.gridy = 0; 87 | girdBagCon.fill = girdBagCon.BOTH; 88 | girdBagCon.insets = new Insets(10,1,10,15); 89 | sNum.setSelectedItem(null); 90 | girdBag.setConstraints(sNum,girdBagCon); 91 | centerPanel.add(sNum); 92 | 93 | jLabel2.setText("姓 名:"); 94 | jLabel2.setFont(new Font("Dialog",0,12)); 95 | girdBagCon = new GridBagConstraints(); 96 | girdBagCon.gridx = 2; 97 | girdBagCon.gridy = 0; 98 | girdBagCon.insets = new Insets(10,15,10,1); 99 | girdBag.setConstraints(jLabel2,girdBagCon); 100 | centerPanel.add(jLabel2); 101 | 102 | girdBagCon = new GridBagConstraints(); 103 | girdBagCon.gridx = 3; 104 | girdBagCon.gridy = 0; 105 | girdBagCon.insets = new Insets(10,1,10,10); 106 | sName.setEnabled(false); 107 | girdBag.setConstraints(sName,girdBagCon); 108 | centerPanel.add(sName); 109 | 110 | jLabel3.setText("选择课程:"); 111 | jLabel3.setFont(new Font("Dialog",0,12)); 112 | girdBagCon = new GridBagConstraints(); 113 | girdBagCon.gridx = 0; 114 | girdBagCon.gridy = 1; 115 | girdBagCon.insets = new Insets(10,10,10,1); 116 | girdBag.setConstraints(jLabel3,girdBagCon); 117 | centerPanel.add(jLabel3); 118 | 119 | CrsBean getId = new CrsBean(); 120 | s = getId.getAllName(); 121 | cName = new JComboBox(s); 122 | 123 | girdBagCon = new GridBagConstraints(); 124 | girdBagCon.gridx = 1; 125 | girdBagCon.gridy = 1; 126 | girdBagCon.fill = girdBagCon.BOTH; 127 | girdBagCon.insets = new Insets(10,1,10,15); 128 | cName.setSelectedItem(null); 129 | girdBag.setConstraints(cName,girdBagCon); 130 | centerPanel.add(cName); 131 | 132 | jLabel4.setText("课程编码:"); 133 | jLabel4.setFont(new Font("Dialog",0,12)); 134 | girdBagCon = new GridBagConstraints(); 135 | girdBagCon.gridx = 2; 136 | girdBagCon.gridy = 1; 137 | girdBagCon.insets = new Insets(10,15,10,1); 138 | girdBag.setConstraints(jLabel4,girdBagCon); 139 | centerPanel.add(jLabel4); 140 | 141 | girdBagCon = new GridBagConstraints(); 142 | girdBagCon.gridx = 3; 143 | girdBagCon.gridy = 1; 144 | girdBagCon.insets = new Insets(10,1,10,10); 145 | cNum.setEditable(false); 146 | girdBag.setConstraints(cNum,girdBagCon); 147 | centerPanel.add(cNum); 148 | 149 | jLabel5.setText("授课老师:"); 150 | jLabel5.setFont(new Font("Dialog",0,12)); 151 | girdBagCon = new GridBagConstraints(); 152 | girdBagCon.gridx = 0; 153 | girdBagCon.gridy = 2; 154 | girdBagCon.insets = new Insets(10,10,10,1); 155 | girdBag.setConstraints(jLabel5,girdBagCon); 156 | centerPanel.add(jLabel5); 157 | 158 | girdBagCon = new GridBagConstraints(); 159 | girdBagCon.gridx = 1; 160 | girdBagCon.gridy = 2; 161 | girdBagCon.insets = new Insets(10,1,10,15); 162 | cTeacher.setEditable(false); 163 | girdBag.setConstraints(cTeacher,girdBagCon); 164 | centerPanel.add(cTeacher); 165 | 166 | jLabel6.setText("授课地点:"); 167 | jLabel6.setFont(new Font("Dialog",0,12)); 168 | girdBagCon = new GridBagConstraints(); 169 | girdBagCon.gridx = 2; 170 | girdBagCon.gridy = 2; 171 | girdBagCon.insets = new Insets(10,15,10,1); 172 | girdBag.setConstraints(jLabel6,girdBagCon); 173 | centerPanel.add(jLabel6); 174 | 175 | girdBagCon = new GridBagConstraints(); 176 | girdBagCon.gridx = 3; 177 | girdBagCon.insets = new Insets(10,1,10,10); 178 | Cplace.setEditable(false); 179 | girdBag.setConstraints(Cplace,girdBagCon); 180 | centerPanel.add(Cplace); 181 | 182 | contentPane.add(centerPanel,BorderLayout.CENTER); 183 | 184 | sNum.addActionListener(this); 185 | cName.addActionListener(this); 186 | } 187 | 188 | /** 189 | * 下部面板的布局 190 | */ 191 | public void downInit(){ 192 | selectCourse.setText("选课"); 193 | selectCourse.setFont(new Font("Dialog",0,12)); 194 | downPanel.add(selectCourse); 195 | cancel.setText("取消"); 196 | cancel.setFont(new Font("Dialog",0,12)); 197 | downPanel.add(cancel); 198 | 199 | contentPane.add(downPanel,BorderLayout.SOUTH); 200 | 201 | //添加事件侦听 202 | cancel.addActionListener(this); 203 | selectCourse.addActionListener(this); 204 | } 205 | 206 | 207 | /** 208 | * 事件处理 209 | */ 210 | public void actionPerformed(ActionEvent e) { 211 | Object obj = e.getSource(); 212 | 213 | if (obj == selectCourse) { //增加 214 | cNum.setEnabled(false); 215 | cName.setEditable(false); 216 | cTeacher.setEditable(false); 217 | Cplace.setEditable(false); 218 | sNum.setEditable(false); 219 | sName.setEditable(false); 220 | 221 | selectCourse.setEnabled(false); 222 | cancel.setEnabled(false); 223 | 224 | csBean crsAdd = new csBean(); 225 | crsAdd.csAdd(cNum.getText(),(String)sNum.getSelectedItem()); 226 | 227 | this.dispose(); 228 | SelectCourse sc = new SelectCourse(); 229 | sc.downInit(); 230 | sc.pack(); 231 | sc.setVisible(true); 232 | } 233 | else if (obj == cancel) { //退出 234 | this.dispose(); 235 | } 236 | else if (obj == sNum) { //选择学号 237 | StuBean sN = new StuBean(); 238 | sName.setText(sN.stuSearch((String)sNum.getSelectedItem())[0]); 239 | } 240 | else if (obj == cName) { //选择课程号 241 | CrsBean cSname = new CrsBean(); 242 | cNum.setText(cSname.crsNameSear((String)cName.getSelectedItem())[5]); 243 | cTeacher.setText(cSname.crsNameSear((String)cName.getSelectedItem())[1]); 244 | Cplace.setText(cSname.crsNameSear((String)cName.getSelectedItem())[2]); 245 | } 246 | } 247 | 248 | 249 | } 250 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuBean.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.sql.*; 4 | import javax.swing.*; 5 | 6 | /** 7 | * 有关学生信息数据库操作的类 8 | */ 9 | public class StuBean { 10 | String sql; 11 | ResultSet rs = null; 12 | 13 | String sNum; 14 | String sName; 15 | String sSex; 16 | String sBirth; 17 | String sHome; 18 | String sEthnic; 19 | String sYear; 20 | String sMajor; 21 | String sCollege; 22 | 23 | String sCourse; 24 | 25 | String colName;//列名 26 | String colValue;//列值 27 | String colValue2;//列值 28 | 29 | int stuId;//学生的新学号 30 | 31 | /** 32 | * 添加学生信息 33 | */ 34 | public void stuAdd(String Snum,String name, String sex, String birth, String home, String ethnic, String year, String major, String college){ 35 | 36 | Database DB = new Database(); 37 | this.sNum = Snum; 38 | this.sName = name; 39 | this.sSex = sex; 40 | this.sBirth = birth; 41 | this.sHome = home; 42 | this.sEthnic = ethnic; 43 | this.sYear = year; 44 | this.sMajor = major; 45 | this.sCollege = college; 46 | 47 | if(sName == null||sName.equals("")){ 48 | JOptionPane.showMessageDialog(null, "请输入学生姓名", "错误", JOptionPane.ERROR_MESSAGE); 49 | return; 50 | } 51 | else{ 52 | String numS = "1"; 53 | 54 | sql = "insert into student(snum, sname,ssex,sbirth,shome,sethnic,syear,smajor,scollege) values ('"+sNum+"','"+sName+"','"+sSex+"','"+sBirth+"','"+sHome+"','"+sEthnic+"','"+sYear+"','"+sMajor+"','"+sCollege+"')"; 55 | try{ 56 | DB.OpenConn(); 57 | System.out.println("ksadhfasdf"); 58 | DB.executeUpdate(sql); 59 | System.out.println("ksadhfasdf"); 60 | JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!"); 61 | 62 | } 63 | catch(Exception e){ 64 | System.out.println(e); 65 | JOptionPane.showMessageDialog(null, "保存失败", "错误", JOptionPane.ERROR_MESSAGE); 66 | } 67 | finally { 68 | DB.closeStmt(); 69 | DB.closeConn(); 70 | } 71 | } 72 | } 73 | 74 | /** 75 | * 修改学生信息 76 | */ 77 | public void stuModify(String num, String name, String sex, String birth, String home, String ethnic, String year, String major, String college){ 78 | 79 | Database DB = new Database(); 80 | 81 | this.sNum = num; 82 | this.sName = name; 83 | this.sSex = sex; 84 | this.sBirth = birth; 85 | this.sHome = home; 86 | this.sEthnic = ethnic; 87 | this.sYear = year; 88 | this.sMajor = major; 89 | this.sCollege = college; 90 | 91 | if(sName == null||sName.equals("")){ 92 | JOptionPane.showMessageDialog(null, "请输入学生姓名", "错误", JOptionPane.ERROR_MESSAGE); 93 | return; 94 | } 95 | else{ 96 | //sql = "update student set sname = '"+sName+"', ssex = '"+sSex+"', sbirth = '"+sBirth+"', shome = '"+sHome+"', sethnic = '"+sEthnic+"', syear = '"+sYear+"', smajor = '"+sMajor+"', scollege = '"+sCollege+"' where snum = "+Integer.parseInt(sNum)+""; 97 | sql = "update student set sname = '"+sName+"', ssex = '"+sSex+"', sbirth = '"+sBirth+"', shome = '"+sHome+"', sethnic = '"+sEthnic+"', syear = '"+sYear+"', smajor = '"+sMajor+"', scollege = '"+sCollege+"' where snum = '"+sNum+"'"; 98 | try{ 99 | DB.OpenConn(); 100 | int k = DB.executeUpdate(sql); 101 | if(k == 1)JOptionPane.showMessageDialog(null,"成功修改一条新的纪录!"); 102 | } 103 | catch(Exception e){ 104 | System.out.println(e); 105 | JOptionPane.showMessageDialog(null, "更新失败", "错误", JOptionPane.ERROR_MESSAGE); 106 | } 107 | finally { 108 | DB.closeStmt(); 109 | DB.closeConn(); 110 | } 111 | } 112 | } 113 | 114 | /** 115 | * 删除学生信息 116 | */ 117 | public void stuDel(String num){ 118 | 119 | Database DB = new Database(); 120 | this.sNum = num; 121 | 122 | sql = "delete from student where snum = '"+sNum+"'"; 123 | try{ 124 | DB.OpenConn(); 125 | DB.executeUpdate(sql); 126 | JOptionPane.showMessageDialog(null,"成功删除一条新的纪录!"); 127 | } 128 | catch(Exception e){ 129 | System.out.println(e); 130 | JOptionPane.showMessageDialog(null, "删除失败", "错误", JOptionPane.ERROR_MESSAGE); 131 | } 132 | finally { 133 | DB.closeStmt(); 134 | DB.closeConn(); 135 | } 136 | } 137 | 138 | /** 139 | * 根据学号查询学生信息 140 | */ 141 | public String[] stuSearch(String num){ 142 | 143 | Database DB = new Database(); 144 | this.sNum = num; 145 | String[] s = new String[8]; 146 | sql = "select * from student where snum = '"+sNum+"'"; 147 | 148 | try{ 149 | DB.OpenConn(); 150 | rs = DB.executeQuery(sql); 151 | if(rs.next()){ 152 | s[0] = rs.getString("sname"); 153 | s[1] = rs.getString("ssex"); 154 | s[2] = rs.getString("sethnic"); 155 | s[3] = rs.getString("shome"); 156 | s[4] = rs.getString("syear"); 157 | s[5] = rs.getString("smajor"); 158 | s[6] = rs.getString("scollege"); 159 | s[7] = rs.getString("sbirth"); 160 | } 161 | else 162 | s = null; 163 | } 164 | catch(Exception e){ 165 | } 166 | finally { 167 | DB.closeStmt(); 168 | DB.closeConn(); 169 | } 170 | return s; 171 | } 172 | 173 | /** 174 | * 学生信息综合查询(按照一个条件进行查询) 175 | */ 176 | public String[][] stuAllSearch(String colname,String colvalue){ 177 | this.colName = colname; 178 | this.colValue = colvalue; 179 | 180 | Database DB = new Database(); 181 | String[][] sn = null; 182 | int row = 0; 183 | int i = 0; 184 | 185 | //DB.toGBK(colvalue); 186 | 187 | if(colValue == null||colValue.equals("")){ 188 | sql = "select * from student"; 189 | } 190 | else{ 191 | sql = "select * from student where "+colName+" = '"+colValue+"'"; 192 | } 193 | try{ 194 | DB.OpenConn(); 195 | rs = DB.executeQuery(sql); 196 | 197 | if(rs.last()){ 198 | row = rs.getRow(); 199 | } 200 | 201 | if(row == 0){ 202 | sn = null; 203 | } 204 | else{ 205 | sn = new String[row][9]; 206 | rs.first(); 207 | rs.previous(); 208 | while(rs.next()){ 209 | sn[i][0] = rs.getString("snum"); 210 | sn[i][1] = rs.getString("sname"); 211 | sn[i][2] = rs.getString("ssex"); 212 | sn[i][3] = rs.getString("sethnic"); 213 | sn[i][4] = rs.getString("shome"); 214 | sn[i][5] = rs.getString("syear"); 215 | sn[i][6] = rs.getString("smajor"); 216 | sn[i][7] = rs.getString("scollege"); 217 | sn[i][8] = rs.getString("sbirth"); 218 | i++; 219 | } 220 | } 221 | } 222 | catch(Exception e){ 223 | } 224 | finally { 225 | DB.closeStmt(); 226 | DB.closeConn(); 227 | } 228 | return sn; 229 | } 230 | 231 | /** 232 | * 学生信息综合查询(查询某范围内的记录) 233 | */ 234 | public String[][] stuAllSearch(String colname,String colvalue,String colvalue2){ 235 | this.colName = colname; 236 | this.colValue = colvalue; 237 | this.colValue2 = colvalue2; 238 | 239 | Database DB = new Database(); 240 | String[][] sn = null; 241 | int row = 0; 242 | int i = 0; 243 | 244 | sql = "select * from student where "+colName+" between "+colValue+" and "+colValue2+""; 245 | try{ 246 | DB.OpenConn(); 247 | rs = DB.executeQuery(sql); 248 | 249 | if(rs.last()){ 250 | row = rs.getRow(); 251 | } 252 | 253 | if(row == 0){ 254 | sn = null; 255 | } 256 | else{ 257 | sn = new String[row][9]; 258 | rs.first(); 259 | rs.previous(); 260 | while(rs.next()){ 261 | sn[i][0] = rs.getString("snum"); 262 | sn[i][1] = rs.getString("sname"); 263 | sn[i][2] = rs.getString("ssex"); 264 | sn[i][3] = rs.getString("sethnic"); 265 | sn[i][4] = rs.getString("shome"); 266 | sn[i][5] = rs.getString("syear"); 267 | sn[i][6] = rs.getString("smajor"); 268 | sn[i][7] = rs.getString("scollege"); 269 | sn[i][8] = rs.getString("sbirth"); 270 | i++; 271 | } 272 | } 273 | } 274 | catch(Exception e){ 275 | } 276 | finally { 277 | DB.closeStmt(); 278 | DB.closeConn(); 279 | } 280 | return sn; 281 | } 282 | 283 | public String[][] stuSearchBySimple(String course){ 284 | this.sCourse = course; 285 | ResultSet rSet,rrSet; 286 | String LinCNUM = null; 287 | Database DB = new Database(); 288 | String[][] sn = null; 289 | String[] snnStrings = null; 290 | int row = 0; 291 | int i = 0; 292 | int j = 0; 293 | String sql1 = "select course.* from course where course.cname='"+sCourse+"'"; 294 | String sql3 = null; 295 | 296 | try{ 297 | DB.OpenConn(); 298 | rSet = DB.executeQuery(sql1); 299 | 300 | if(rSet.last()){ 301 | row = rSet.getRow(); 302 | } 303 | 304 | if(row == 0){ 305 | LinCNUM = null; 306 | } 307 | else{ 308 | 309 | rSet.first(); 310 | rSet.previous(); 311 | while(rSet.next()){ 312 | LinCNUM = rSet.getString("cnum"); 313 | } 314 | } 315 | System.out.println(LinCNUM); 316 | String sql2 = "select sc.snum from sc where sc.cnum='"+LinCNUM+"' order by sc.grade desc"; 317 | rrSet = DB.executeQuery(sql2); 318 | if(rrSet.last()){ 319 | row = rrSet.getRow(); 320 | } 321 | 322 | if(row == 0){ 323 | snnStrings = null; 324 | } 325 | else{ 326 | i = 0; 327 | snnStrings = new String[row]; 328 | sn = new String[row][9]; 329 | System.out.println(""+row); 330 | rrSet.first(); 331 | rrSet.previous(); 332 | while(rrSet.next()){ 333 | snnStrings[i] = rrSet.getString("snum"); 334 | sql3 = "select * from student where snum='"+snnStrings[i]+"'"; 335 | rs = DB.executeQuery(sql3); 336 | 337 | while(rs.next()){ 338 | sn[j][0] = rs.getString("snum"); 339 | sn[j][1] = rs.getString("sname"); 340 | sn[j][2] = rs.getString("ssex"); 341 | sn[j][3] = rs.getString("sethnic"); 342 | sn[j][4] = rs.getString("shome"); 343 | sn[j][5] = rs.getString("syear"); 344 | sn[j][6] = rs.getString("smajor"); 345 | sn[j][7] = rs.getString("scollege"); 346 | sn[j][8] = rs.getString("sbirth"); 347 | j++; 348 | } 349 | 350 | i++; 351 | } 352 | } 353 | 354 | } 355 | catch(Exception e){ 356 | e.printStackTrace(); 357 | } 358 | finally { 359 | DB.closeStmt(); 360 | DB.closeConn(); 361 | } 362 | System.out.println(sn[1][1]); 363 | return sn; 364 | //return snnStrings; 365 | 366 | } 367 | 368 | 369 | public String[][] stuSearchBypoint(){ 370 | String sCourse = "编译原理"; 371 | ResultSet rSet,rrSet; 372 | String LinCNUM = null; 373 | Database DB = new Database(); 374 | String[][] sn = null; 375 | String[] snnStrings = null; 376 | int row = 0; 377 | int i = 0; 378 | int j = 0; 379 | String sql1 = "select course.* from course where course.cname='"+sCourse+"'"; 380 | String sql3 = null; 381 | 382 | try{ 383 | DB.OpenConn(); 384 | rSet = DB.executeQuery(sql1); 385 | 386 | if(rSet.last()){ 387 | row = rSet.getRow(); 388 | } 389 | 390 | if(row == 0){ 391 | LinCNUM = null; 392 | } 393 | else{ 394 | 395 | rSet.first(); 396 | rSet.previous(); 397 | while(rSet.next()){ 398 | LinCNUM = rSet.getString("cnum"); 399 | } 400 | } 401 | System.out.println(LinCNUM); 402 | String sql2 = "select sc.snum from sc where sc.cnum='"+LinCNUM+"' order by sc.grade desc"; 403 | rrSet = DB.executeQuery(sql2); 404 | if(rrSet.last()){ 405 | row = rrSet.getRow(); 406 | } 407 | 408 | if(row == 0){ 409 | snnStrings = null; 410 | } 411 | else{ 412 | i = 0; 413 | snnStrings = new String[row]; 414 | sn = new String[row][9]; 415 | System.out.println(""+row); 416 | rrSet.first(); 417 | rrSet.previous(); 418 | while(rrSet.next()){ 419 | snnStrings[i] = rrSet.getString("snum"); 420 | sql3 = "select * from student where snum='"+snnStrings[i]+"'"; 421 | rs = DB.executeQuery(sql3); 422 | 423 | while(rs.next()){ 424 | sn[j][0] = rs.getString("snum"); 425 | sn[j][1] = rs.getString("sname"); 426 | sn[j][2] = rs.getString("ssex"); 427 | sn[j][3] = rs.getString("sethnic"); 428 | sn[j][4] = rs.getString("shome"); 429 | sn[j][5] = rs.getString("syear"); 430 | sn[j][6] = rs.getString("smajor"); 431 | sn[j][7] = rs.getString("scollege"); 432 | sn[j][8] = rs.getString("sbirth"); 433 | j++; 434 | } 435 | 436 | i++; 437 | } 438 | } 439 | 440 | } 441 | catch(Exception e){ 442 | e.printStackTrace(); 443 | } 444 | finally { 445 | DB.closeStmt(); 446 | DB.closeConn(); 447 | } 448 | System.out.println(sn[1][1]); 449 | return sn; 450 | 451 | } 452 | 453 | 454 | /** 455 | * 获得student表中的所有学号snum 456 | */ 457 | public String[] getAllId(){ 458 | String[] s = null; 459 | int row = 0; 460 | int i = 0; 461 | Database DB = new Database(); 462 | sql = "select snum from student"; 463 | 464 | try{ 465 | DB.OpenConn(); 466 | rs = DB.executeQuery(sql); 467 | if(rs.last()){ 468 | row = rs.getRow(); 469 | } 470 | 471 | if(row == 0){ 472 | s = null; 473 | } 474 | else{ 475 | s = new String[row]; 476 | rs.first(); 477 | rs.previous(); 478 | while(rs.next()){ 479 | s[i] = rs.getString(1); 480 | i++; 481 | } 482 | } 483 | } 484 | catch(Exception e){ 485 | e.printStackTrace(); 486 | } 487 | finally { 488 | DB.closeStmt(); 489 | DB.closeConn(); 490 | } 491 | return s; 492 | } 493 | } 494 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuInfo.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 学生信息综合管理类 9 | * 提供主界面,供其他类继承 10 | */ 11 | public class StuInfo extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | JPanel centerPanel = new JPanel(); 18 | JPanel upPanel = new JPanel(); 19 | JPanel downPanel = new JPanel(); 20 | 21 | //框架的大小 22 | Dimension faceSize = new Dimension(800, 500); 23 | 24 | JLabel jLabel1 = new JLabel(); 25 | JLabel jLabel2 = new JLabel(); 26 | JLabel jLabel3 = new JLabel(); 27 | JLabel jLabel4 = new JLabel(); 28 | JLabel jLabel5 = new JLabel(); 29 | JLabel jLabel6 = new JLabel(); 30 | JLabel jLabel7 = new JLabel(); 31 | JLabel jLabel8 = new JLabel(); 32 | JLabel jLabel9 = new JLabel(); 33 | JTextField sNum = new JTextField(15); 34 | JTextField sName = new JTextField(15); 35 | JTextField sSex = new JTextField(15); 36 | JTextField sSethnic = new JTextField(15); 37 | JTextField sBirth = new JTextField(15); 38 | JTextField sYear = new JTextField(15); 39 | JTextField sMajor = new JTextField(15); 40 | JTextField sCollege = new JTextField(15); 41 | JTextField sHome = new JTextField(46); 42 | JButton searchInfo = new JButton(); 43 | JButton addInfo = new JButton(); 44 | JButton modifyInfo = new JButton(); 45 | JButton deleteInfo = new JButton(); 46 | JButton clearInfo = new JButton(); 47 | JButton saveInfo = new JButton(); 48 | JButton eixtInfo = new JButton(); 49 | 50 | JButton jBSee = new JButton(); 51 | JButton jBSearch = new JButton(); 52 | JButton jBExit = new JButton(); 53 | JButton jBSum = new JButton(); 54 | JButton jBGrade = new JButton(); 55 | 56 | GridBagLayout girdBag = new GridBagLayout(); 57 | GridBagConstraints girdBagCon; 58 | 59 | public StuInfo() { 60 | //设置框架的大小 61 | this.setSize(faceSize); 62 | //设置标题 63 | this.setTitle("学生综合信息管理"); 64 | this.setResizable(false); 65 | 66 | try { 67 | Init(); 68 | } 69 | catch(Exception e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | 74 | public void Init() throws Exception { 75 | contentPane = this.getContentPane(); 76 | contentPane.setLayout(new BorderLayout()); 77 | 78 | //中部面板的布局 79 | centerPanel.setLayout(girdBag); 80 | 81 | jLabel1.setText("学 号:"); 82 | jLabel1.setFont(new Font("Dialog",0,12)); 83 | girdBagCon = new GridBagConstraints(); 84 | girdBagCon.gridx = 0; 85 | girdBagCon.gridy = 0; 86 | girdBagCon.insets = new Insets(10,10,10,1); 87 | girdBag.setConstraints(jLabel1,girdBagCon); 88 | centerPanel.add(jLabel1); 89 | 90 | girdBagCon = new GridBagConstraints(); 91 | girdBagCon.gridx = 1; 92 | girdBagCon.gridy = 0; 93 | girdBagCon.insets = new Insets(10,1,10,15); 94 | girdBag.setConstraints(sNum,girdBagCon); 95 | centerPanel.add(sNum); 96 | 97 | jLabel2.setText("姓 名:"); 98 | jLabel2.setFont(new Font("Dialog",0,12)); 99 | girdBagCon = new GridBagConstraints(); 100 | girdBagCon.gridx = 2; 101 | girdBagCon.gridy = 0; 102 | girdBagCon.insets = new Insets(10,15,10,1); 103 | girdBag.setConstraints(jLabel2,girdBagCon); 104 | centerPanel.add(jLabel2); 105 | 106 | girdBagCon = new GridBagConstraints(); 107 | girdBagCon.gridx = 3; 108 | girdBagCon.gridy = 0; 109 | girdBagCon.insets = new Insets(10,1,10,10); 110 | girdBag.setConstraints(sName,girdBagCon); 111 | centerPanel.add(sName); 112 | 113 | jLabel3.setText("性 别:"); 114 | jLabel3.setFont(new Font("Dialog",0,12)); 115 | girdBagCon = new GridBagConstraints(); 116 | girdBagCon.gridx = 0; 117 | girdBagCon.gridy = 1; 118 | girdBagCon.insets = new Insets(10,10,10,1); 119 | girdBag.setConstraints(jLabel3,girdBagCon); 120 | centerPanel.add(jLabel3); 121 | 122 | girdBagCon = new GridBagConstraints(); 123 | girdBagCon.gridx = 1; 124 | girdBagCon.gridy = 1; 125 | girdBagCon.insets = new Insets(10,1,10,15); 126 | girdBag.setConstraints(sSex,girdBagCon); 127 | centerPanel.add(sSex); 128 | 129 | jLabel4.setText("民 族:"); 130 | jLabel4.setFont(new Font("Dialog",0,12)); 131 | girdBagCon = new GridBagConstraints(); 132 | girdBagCon.gridx = 2; 133 | girdBagCon.gridy = 1; 134 | girdBagCon.insets = new Insets(10,15,10,1); 135 | girdBag.setConstraints(jLabel4,girdBagCon); 136 | centerPanel.add(jLabel4); 137 | 138 | girdBagCon = new GridBagConstraints(); 139 | girdBagCon.gridx = 3; 140 | girdBagCon.gridy = 1; 141 | girdBagCon.insets = new Insets(10,1,10,10); 142 | girdBag.setConstraints(sSethnic,girdBagCon); 143 | centerPanel.add(sSethnic); 144 | 145 | jLabel5.setText("出生日期:"); 146 | jLabel5.setFont(new Font("Dialog",0,12)); 147 | girdBagCon = new GridBagConstraints(); 148 | girdBagCon.gridx = 0; 149 | girdBagCon.gridy = 2; 150 | girdBagCon.insets = new Insets(10,10,10,1); 151 | girdBag.setConstraints(jLabel5,girdBagCon); 152 | centerPanel.add(jLabel5); 153 | 154 | girdBagCon = new GridBagConstraints(); 155 | girdBagCon.gridx = 1; 156 | girdBagCon.gridy = 2; 157 | girdBagCon.insets = new Insets(10,1,10,15); 158 | girdBag.setConstraints(sBirth,girdBagCon); 159 | centerPanel.add(sBirth); 160 | 161 | jLabel6.setText("入学时间:"); 162 | jLabel6.setFont(new Font("Dialog",0,12)); 163 | girdBagCon = new GridBagConstraints(); 164 | girdBagCon.gridx = 2; 165 | girdBagCon.gridy = 2; 166 | girdBagCon.insets = new Insets(10,15,10,1); 167 | girdBag.setConstraints(jLabel6,girdBagCon); 168 | centerPanel.add(jLabel6); 169 | 170 | girdBagCon = new GridBagConstraints(); 171 | girdBagCon.gridx = 3; 172 | girdBagCon.insets = new Insets(10,1,10,10); 173 | girdBag.setConstraints(sYear,girdBagCon); 174 | centerPanel.add(sYear); 175 | 176 | jLabel7.setText("学 院:"); 177 | jLabel7.setFont(new Font("Dialog",0,12)); 178 | girdBagCon = new GridBagConstraints(); 179 | girdBagCon.gridx = 0; 180 | girdBagCon.gridy = 3; 181 | girdBagCon.insets = new Insets(10,10,10,1); 182 | girdBag.setConstraints(jLabel7,girdBagCon); 183 | centerPanel.add(jLabel7); 184 | 185 | girdBagCon = new GridBagConstraints(); 186 | girdBagCon.gridx = 1; 187 | girdBagCon.gridy = 3; 188 | girdBagCon.insets = new Insets(10,1,10,15); 189 | girdBag.setConstraints(sCollege,girdBagCon); 190 | centerPanel.add(sCollege); 191 | 192 | jLabel8.setText("专 业:"); 193 | jLabel8.setFont(new Font("Dialog",0,12)); 194 | girdBagCon = new GridBagConstraints(); 195 | girdBagCon.gridx = 2; 196 | girdBagCon.gridy = 3; 197 | girdBagCon.insets = new Insets(10,15,10,1); 198 | girdBag.setConstraints(jLabel8,girdBagCon); 199 | centerPanel.add(jLabel8); 200 | 201 | girdBagCon = new GridBagConstraints(); 202 | girdBagCon.gridx = 3; 203 | girdBagCon.gridy = 3; 204 | girdBagCon.insets = new Insets(10,1,10,10); 205 | girdBag.setConstraints(sMajor,girdBagCon); 206 | centerPanel.add(sMajor); 207 | 208 | jLabel9.setText("籍 贯:"); 209 | jLabel9.setFont(new Font("Dialog",0,12)); 210 | girdBagCon = new GridBagConstraints(); 211 | girdBagCon.gridx = 0; 212 | girdBagCon.gridy = 4; 213 | girdBagCon.insets = new Insets(10,10,10,1); 214 | girdBag.setConstraints(jLabel9,girdBagCon); 215 | centerPanel.add(jLabel9); 216 | 217 | girdBagCon = new GridBagConstraints(); 218 | girdBagCon.gridx = 1; 219 | girdBagCon.gridy = 4; 220 | girdBagCon.gridwidth = 3; 221 | girdBagCon.insets = new Insets(10,1,10,10); 222 | girdBag.setConstraints(sHome,girdBagCon); 223 | centerPanel.add(sHome); 224 | 225 | contentPane.add(centerPanel,BorderLayout.CENTER); 226 | 227 | sNum.setEditable(false); 228 | sName.setEditable(false); 229 | sSex.setEditable(false); 230 | sSethnic.setEditable(false); 231 | sBirth.setEditable(false); 232 | sYear.setEditable(false); 233 | sMajor.setEditable(false); 234 | sCollege.setEditable(false); 235 | sHome.setEditable(false); 236 | } 237 | 238 | /** 239 | * 下部面板的布局 240 | */ 241 | public void downInit(){ 242 | searchInfo.setText("查询"); 243 | searchInfo.setFont(new Font("Dialog",0,12)); 244 | downPanel.add(searchInfo); 245 | addInfo.setText("增加"); 246 | addInfo.setFont(new Font("Dialog",0,12)); 247 | downPanel.add(addInfo); 248 | modifyInfo.setText("修改"); 249 | modifyInfo.setFont(new Font("Dialog",0,12)); 250 | downPanel.add(modifyInfo); 251 | deleteInfo.setText("删除"); 252 | deleteInfo.setFont(new Font("Dialog",0,12)); 253 | downPanel.add(deleteInfo); 254 | saveInfo.setText("保存"); 255 | saveInfo.setFont(new Font("Dialog",0,12)); 256 | downPanel.add(saveInfo); 257 | clearInfo.setText("清空"); 258 | clearInfo.setFont(new Font("Dialog",0,12)); 259 | downPanel.add(clearInfo); 260 | eixtInfo.setText("退出"); 261 | eixtInfo.setFont(new Font("Dialog",0,12)); 262 | downPanel.add(eixtInfo); 263 | 264 | contentPane.add(downPanel,BorderLayout.SOUTH); 265 | 266 | //添加事件侦听 267 | searchInfo.addActionListener(this); 268 | addInfo.addActionListener(this); 269 | modifyInfo.addActionListener(this); 270 | deleteInfo.addActionListener(this); 271 | saveInfo.addActionListener(this); 272 | clearInfo.addActionListener(this); 273 | eixtInfo.addActionListener(this); 274 | 275 | modifyInfo.setEnabled(false); 276 | deleteInfo.setEnabled(false); 277 | saveInfo.setEnabled(false); 278 | clearInfo.setEnabled(false); 279 | } 280 | 281 | /** 282 | * 事件处理 283 | */ 284 | public void actionPerformed(ActionEvent e) { 285 | Object obj = e.getSource(); 286 | if (obj == searchInfo) { //查询 287 | } 288 | else if (obj == addInfo) { //增加 289 | } 290 | else if (obj == modifyInfo) { //修改 291 | } 292 | else if (obj == deleteInfo) { //删除 293 | } 294 | else if (obj == saveInfo) { //保存 295 | } 296 | else if (obj == clearInfo) { //清空 297 | setNull(); 298 | } 299 | else if (obj == eixtInfo) { //退出 300 | this.dispose(); 301 | } 302 | } 303 | 304 | /** 305 | * 将文本框清空 306 | */ 307 | void setNull(){ 308 | sNum.setText(null); 309 | sName.setText(null); 310 | sSex.setText(null); 311 | sSethnic.setText(null); 312 | sBirth.setText(null); 313 | sYear.setText(null); 314 | sMajor.setText(null); 315 | sCollege.setText(null); 316 | sHome.setText(null); 317 | } 318 | 319 | 320 | } 321 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuInfoSearchSnum.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | 5 | import java.awt.*; 6 | import java.awt.event.*; 7 | 8 | /** 9 | * 学生信息管理模块 10 | * 根据学号查询学生的信息,以供调用者修改或删除 11 | */ 12 | public class StuInfoSearchSnum extends JDialog implements ActionListener{ 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | Container contentPane; 18 | String[] s; 19 | //框架的大小 20 | Dimension faceSize = new Dimension(300, 100); 21 | JLabel jLabel1 = new JLabel(); 22 | JComboBox selectSnum; 23 | JButton searchInfo = new JButton(); 24 | 25 | 26 | public StuInfoSearchSnum(JFrame frame) { 27 | super(frame, true); 28 | this.setTitle("学号查询"); 29 | this.setResizable(false); 30 | try { 31 | Init(); 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | //设置运行位置,使对话框居中 37 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 38 | this.setLocation( (int) (screenSize.width - 400) / 2 , 39 | (int) (screenSize.height - 300) / 2 +45); 40 | 41 | } 42 | 43 | private void Init() throws Exception { 44 | this.setSize(faceSize); 45 | contentPane = this.getContentPane(); 46 | contentPane.setLayout(new FlowLayout()); 47 | 48 | jLabel1.setText("请输入或者选择学号:"); 49 | jLabel1.setFont(new Font("Dialog",0,12)); 50 | contentPane.add(jLabel1); 51 | 52 | StuBean getId = new StuBean(); 53 | s = getId.getAllId(); 54 | if (s != null)selectSnum = new JComboBox(s); 55 | else {JOptionPane.showMessageDialog(null, "没有记录", "错误", JOptionPane.ERROR_MESSAGE); 56 | //selectSnum = new JComboBox(NULLSTRING); 57 | return; 58 | } 59 | selectSnum.setEditable(true); 60 | selectSnum.setFont(new Font("Dialog",0,12)); 61 | contentPane.add(selectSnum); 62 | 63 | searchInfo.setText("查询"); 64 | searchInfo.setFont(new Font("Dialog",0,12)); 65 | contentPane.add(searchInfo); 66 | 67 | searchInfo.addActionListener(this); 68 | } 69 | 70 | /** 71 | * 事件处理 72 | */ 73 | public void actionPerformed(ActionEvent e) { 74 | Object obj = e.getSource(); 75 | if (obj == selectSnum) { //退出 76 | this.dispose(); 77 | } 78 | else if (obj == searchInfo) { //修改 79 | this.dispose(); 80 | } 81 | } 82 | 83 | /** 84 | * 返回选择的学号 85 | */ 86 | public String getSnum(){ 87 | return (String)this.selectSnum.getSelectedItem(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuMain.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.awt.*; 4 | import java.awt.event.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 学生管理系统主界面 9 | */ 10 | public class StuMain extends JFrame implements ActionListener{ 11 | 12 | 13 | 14 | 15 | //建立菜单栏 16 | //建立“系统管理”菜单组 17 | 18 | /** 19 | * 20 | */ 21 | private static final long serialVersionUID = 1L; 22 | JLabel J1 = new JLabel("学生管理"); 23 | JLabel J2 = new JLabel("课程管理"); 24 | JLabel J3 = new JLabel("成绩管理"); 25 | JLabel J4 = new JLabel("信息查询"); 26 | JLabel J5 = new JLabel("学生查询"); 27 | JLabel J6 = new JLabel("课程查询"); 28 | JLabel J7 = new JLabel("成绩查询"); 29 | 30 | 31 | JButton buttonExit = new JButton("退出"); 32 | JButton buttonAddS = new JButton("增加"); 33 | JButton buttonEditS=new JButton("修改"); 34 | JButton buttonDeleteS=new JButton("删除"); 35 | JButton buttonChooseS = new JButton("选课"); 36 | //建立“课程管理”菜单组 37 | JButton buttonAddC=new JButton("增加"); 38 | JButton buttonEditC=new JButton("修改"); 39 | JButton buttonDeleteC=new JButton("删除"); 40 | 41 | JButton buttonAddG=new JButton("增加"); 42 | JButton buttonEditG=new JButton("修改"); 43 | JButton buttonDELG=new JButton("删除"); 44 | //建立“信息查询”菜单组 45 | 46 | JButton buttonSearchStuBySnum=new JButton("按学号"); 47 | JButton buttonSearchStuBySname=new JButton("按姓名"); 48 | JButton buttonSearchStuBySsex=new JButton("按性别"); 49 | JButton buttonSearchStuByScollege=new JButton("按学院"); 50 | JButton buttonSearchStuBySmajor=new JButton("按专业"); 51 | 52 | JButton buttonSearchStuByCname=new JButton("按课程名称"); 53 | JButton buttonSearchStuByCteacher=new JButton("按授课教师"); 54 | 55 | JButton buttonSearchMutGrd=new JButton("查询所有成绩"); 56 | public StuMain() { 57 | enableEvents(AWTEvent.WINDOW_EVENT_MASK); 58 | //添加框架的关闭事件处理 59 | this.pack(); 60 | //设置框架的大小 61 | //设置标题 62 | this.setTitle("学生管理系统"); 63 | 64 | 65 | 66 | 67 | try { 68 | 69 | 70 | 71 | this.setSize(700,400); 72 | this.setLocation(300,300); 73 | this.setResizable(false); 74 | this.setLayout(new GridBagLayout()); 75 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 76 | this.setBackground(Color.lightGray); 77 | 78 | this.getContentPane().setBackground(Color.getHSBColor(245, 245,245)); 79 | 80 | 81 | 82 | 83 | 84 | Container mPanel = this.getContentPane(); 85 | GridBagConstraints c = new GridBagConstraints(); 86 | c.insets = new Insets(10,0,0,10); 87 | 88 | c.gridx = 0; 89 | c.gridy = 0; 90 | c.gridwidth = 10; 91 | c.fill = GridBagConstraints.BOTH; 92 | c.anchor = GridBagConstraints.CENTER; 93 | mPanel.add(J1,c); 94 | 95 | 96 | c.gridx = 0; 97 | c.gridy = 1; 98 | c.gridwidth = 1; 99 | c.fill = GridBagConstraints.BOTH; 100 | c.anchor = GridBagConstraints.CENTER; 101 | mPanel.add(J2,c); 102 | 103 | c.gridx = 0; 104 | c.gridy = 2; 105 | c.gridwidth = 1; 106 | c.fill = GridBagConstraints.BOTH; 107 | c.anchor = GridBagConstraints.CENTER; 108 | mPanel.add(J3,c); 109 | 110 | c.gridx = 0; 111 | c.gridy = 4; 112 | c.gridwidth = 1; 113 | c.fill = GridBagConstraints.BOTH; 114 | c.anchor = GridBagConstraints.CENTER; 115 | mPanel.add(J4,c); 116 | 117 | c.gridx = 1; 118 | c.gridy = 0; 119 | c.gridwidth = 1; 120 | c.fill = GridBagConstraints.BOTH; 121 | c.anchor = GridBagConstraints.CENTER; 122 | mPanel.add(buttonAddS,c); 123 | 124 | c.gridx = 2; 125 | c.gridy = 0; 126 | c.gridwidth = 1; 127 | c.fill = GridBagConstraints.BOTH; 128 | c.anchor = GridBagConstraints.CENTER; 129 | mPanel.add(buttonEditS,c); 130 | 131 | c.gridx = 3; 132 | c.gridy = 0; 133 | c.gridwidth = 1; 134 | c.fill = GridBagConstraints.BOTH; 135 | c.anchor = GridBagConstraints.CENTER; 136 | mPanel.add(buttonDeleteS,c); 137 | 138 | c.gridx = 4; 139 | c.gridy = 0; 140 | c.gridwidth = 1; 141 | c.fill = GridBagConstraints.BOTH; 142 | c.anchor = GridBagConstraints.CENTER; 143 | mPanel.add(buttonChooseS,c); 144 | 145 | c.gridx = 1; 146 | c.gridy = 1; 147 | c.gridwidth = 1; 148 | c.fill = GridBagConstraints.BOTH; 149 | c.anchor = GridBagConstraints.CENTER; 150 | mPanel.add(buttonAddC,c); 151 | 152 | c.gridx = 2; 153 | c.gridy = 1; 154 | c.gridwidth = 1; 155 | c.fill = GridBagConstraints.BOTH; 156 | c.anchor = GridBagConstraints.CENTER; 157 | mPanel.add(buttonEditC,c); 158 | 159 | c.gridx = 3; 160 | c.gridy = 1; 161 | c.gridwidth = 1; 162 | c.fill = GridBagConstraints.BOTH; 163 | c.anchor = GridBagConstraints.CENTER; 164 | mPanel.add(buttonDeleteC,c); 165 | 166 | c.gridx = 1; 167 | c.gridy = 2; 168 | c.gridwidth = 1; 169 | c.fill = GridBagConstraints.BOTH; 170 | c.anchor = GridBagConstraints.CENTER; 171 | mPanel.add(buttonAddG,c); 172 | 173 | c.gridx = 2; 174 | c.gridy = 2; 175 | c.gridwidth = 1; 176 | c.fill = GridBagConstraints.BOTH; 177 | c.anchor = GridBagConstraints.CENTER; 178 | mPanel.add(buttonEditG,c); 179 | 180 | c.gridx = 3; 181 | c.gridy = 2; 182 | c.gridwidth = 1; 183 | c.fill = GridBagConstraints.BOTH; 184 | c.anchor = GridBagConstraints.CENTER; 185 | mPanel.add(buttonDELG,c); 186 | 187 | c.gridx = 1; 188 | c.gridy = 3; 189 | c.gridwidth = 1; 190 | c.fill = GridBagConstraints.BOTH; 191 | c.anchor = GridBagConstraints.CENTER; 192 | mPanel.add(J5,c); 193 | 194 | c.gridx = 2; 195 | c.gridy = 3; 196 | c.gridwidth = 1; 197 | c.fill = GridBagConstraints.BOTH; 198 | c.anchor = GridBagConstraints.CENTER; 199 | mPanel.add(buttonSearchStuBySnum,c); 200 | 201 | c.gridx = 3; 202 | c.gridy = 3; 203 | c.gridwidth = 1; 204 | c.fill = GridBagConstraints.BOTH; 205 | c.anchor = GridBagConstraints.CENTER; 206 | mPanel.add(buttonSearchStuBySname,c); 207 | 208 | 209 | c.gridx = 4; 210 | c.gridy = 3; 211 | c.gridwidth = 1; 212 | c.fill = GridBagConstraints.BOTH; 213 | c.anchor = GridBagConstraints.CENTER; 214 | mPanel.add(buttonSearchStuBySsex,c); 215 | 216 | c.gridx = 5; 217 | c.gridy = 3; 218 | c.gridwidth = 1; 219 | c.fill = GridBagConstraints.BOTH; 220 | c.anchor = GridBagConstraints.CENTER; 221 | mPanel.add(buttonSearchStuBySmajor,c); 222 | 223 | c.gridx = 6; 224 | c.gridy = 3; 225 | c.gridwidth = 1; 226 | c.fill = GridBagConstraints.BOTH; 227 | c.anchor = GridBagConstraints.CENTER; 228 | mPanel.add(buttonSearchStuByScollege,c); 229 | 230 | c.gridx = 1; 231 | c.gridy = 4; 232 | c.gridwidth = 1; 233 | c.fill = GridBagConstraints.BOTH; 234 | c.anchor = GridBagConstraints.CENTER; 235 | mPanel.add(J6,c); 236 | 237 | c.gridx = 2; 238 | c.gridy = 4; 239 | c.gridwidth = 1; 240 | c.fill = GridBagConstraints.BOTH; 241 | c.anchor = GridBagConstraints.CENTER; 242 | mPanel.add(buttonSearchStuByCname,c); 243 | 244 | c.gridx = 3; 245 | c.gridy = 4; 246 | c.gridwidth = 1; 247 | c.fill = GridBagConstraints.BOTH; 248 | c.anchor = GridBagConstraints.CENTER; 249 | mPanel.add(buttonSearchStuByCteacher,c); 250 | 251 | c.gridx = 1; 252 | c.gridy = 5; 253 | c.gridwidth = 1; 254 | c.fill = GridBagConstraints.BOTH; 255 | c.anchor = GridBagConstraints.CENTER; 256 | mPanel.add(J7,c); 257 | 258 | c.gridx = 2; 259 | c.gridy = 5; 260 | c.gridwidth = 1; 261 | c.fill = GridBagConstraints.BOTH; 262 | c.anchor = GridBagConstraints.CENTER; 263 | mPanel.add(buttonSearchMutGrd,c); 264 | 265 | c.gridx = 6; 266 | c.gridy = 6; 267 | c.gridwidth = 1; 268 | c.fill = GridBagConstraints.BOTH; 269 | c.anchor = GridBagConstraints.CENTER; 270 | mPanel.add(buttonExit,c); 271 | 272 | //设置文本区域可以换行 273 | 274 | 275 | 276 | 277 | 278 | 279 | buttonExit.addActionListener(this); 280 | buttonAddS.addActionListener(this); 281 | buttonEditS.addActionListener(this); 282 | buttonDeleteS.addActionListener(this); 283 | buttonChooseS.addActionListener(this); 284 | 285 | buttonAddC.addActionListener(this); 286 | buttonEditC.addActionListener(this); 287 | buttonDeleteC.addActionListener(this); 288 | 289 | buttonAddG.addActionListener(this); 290 | buttonEditG.addActionListener(this); 291 | buttonDELG.addActionListener(this); 292 | 293 | 294 | buttonSearchStuBySnum.addActionListener(this); 295 | buttonSearchStuBySname.addActionListener(this); 296 | buttonSearchStuBySsex.addActionListener(this); 297 | buttonSearchStuByScollege.addActionListener(this); 298 | buttonSearchStuBySmajor.addActionListener(this); 299 | buttonSearchStuByCname.addActionListener(this); 300 | buttonSearchStuByCteacher.addActionListener(this); 301 | 302 | buttonSearchMutGrd.addActionListener(this); 303 | 304 | //关闭程序时的操作 305 | this.addWindowListener( 306 | new WindowAdapter(){ 307 | public void windowClosing(WindowEvent e){ 308 | System.exit(0); 309 | } 310 | } 311 | ); 312 | } 313 | catch(Exception e) { 314 | e.printStackTrace(); 315 | } 316 | } 317 | 318 | 319 | 320 | public void actionPerformed(ActionEvent e) { 321 | Object obj = e.getSource(); 322 | if (obj == buttonExit) { //退出 323 | System.exit(0); 324 | } 325 | else if (obj == buttonAddS) { //学生信息增加 326 | AddStuInfo asi = new AddStuInfo(); 327 | asi.downInit(); 328 | asi.pack(); 329 | asi.setVisible(true); 330 | 331 | } 332 | else if (obj == buttonEditS) { //学生信息修改 333 | EditStuInfo esi = new EditStuInfo(); 334 | esi.downInit(); 335 | esi.pack(); 336 | esi.setVisible(true); 337 | } 338 | else if (obj == buttonDeleteS) { //学生信息删出 339 | DelStuInfo dsi = new DelStuInfo(); 340 | dsi.downInit(); 341 | dsi.pack(); 342 | dsi.setVisible(true); 343 | } 344 | else if (obj == buttonChooseS) { //学生选课 345 | SelectCourse sc = new SelectCourse(); 346 | sc.downInit(); 347 | sc.pack(); 348 | sc.setVisible(true); 349 | } 350 | else if (obj == buttonAddC) { //课程增加 351 | AddCourseInfo aci = new AddCourseInfo(); 352 | aci.downInit(); 353 | aci.pack(); 354 | aci.setVisible(true); 355 | } 356 | else if (obj == buttonEditC) { //课程修改 357 | EditCourseInfo eci = new EditCourseInfo(); 358 | eci.downInit(); 359 | eci.pack(); 360 | eci.setVisible(true); 361 | } 362 | else if (obj == buttonDeleteC) { //课程删除 363 | DelCourseInfo dci = new DelCourseInfo(); 364 | dci.downInit(); 365 | dci.pack(); 366 | dci.setVisible(true); 367 | } 368 | else if (obj == buttonAddG) { //成绩增加 369 | AddGradeInfo agi = new AddGradeInfo(); 370 | agi.downInit(); 371 | agi.pack(); 372 | agi.setVisible(true); 373 | } 374 | else if (obj == buttonEditG) { //成绩修改 375 | EditGradeInfo egi = new EditGradeInfo(); 376 | egi.downInit(); 377 | egi.pack(); 378 | egi.setVisible(true); 379 | } 380 | else if (obj == buttonDELG) { //成绩删除 381 | DelGradeInfo egi = new DelGradeInfo(); 382 | egi.downInit(); 383 | egi.pack(); 384 | egi.setVisible(true); 385 | } 386 | 387 | //查询功能的事件处理 388 | else if (obj == buttonSearchStuBySnum) { //按学号查询 389 | StuSearchSnum ssSnum = new StuSearchSnum(); 390 | ssSnum.pack(); 391 | ssSnum.setVisible(true); 392 | } 393 | else if (obj == buttonSearchStuBySname) { //按学姓名查询 394 | StuSearchSname ssSname = new StuSearchSname(); 395 | ssSname.pack(); 396 | ssSname.setVisible(true); 397 | } 398 | else if (obj == buttonSearchStuBySsex) { //按性别查询 399 | StuSearchSsex ssSsex = new StuSearchSsex(); 400 | ssSsex.pack(); 401 | ssSsex.setVisible(true); 402 | } 403 | else if (obj == buttonSearchStuByScollege) { //按学院查询 404 | StuSearchScollege ssScollege = new StuSearchScollege(); 405 | ssScollege.pack(); 406 | ssScollege.setVisible(true); 407 | } 408 | else if (obj == buttonSearchStuBySmajor) { //按专业查询 409 | StuSearchSmajor ssSmajor = new StuSearchSmajor(); 410 | ssSmajor.pack(); 411 | ssSmajor.setVisible(true); 412 | } 413 | else if (obj == buttonSearchStuByCname) { //按课程名查询课程 414 | CourseSearchCname csCname = new CourseSearchCname(); 415 | csCname.pack(); 416 | csCname.setVisible(true); 417 | } 418 | else if (obj == buttonSearchStuByCteacher) { //按授课教师查询课程 419 | CourseSearchCteacher csCteacher = new CourseSearchCteacher(); 420 | csCteacher.pack(); 421 | csCteacher.setVisible(true); 422 | } 423 | else if (obj == buttonSearchMutGrd) { //查询所有科目成绩 424 | GrdSearchAllGrade gsag = new GrdSearchAllGrade(); 425 | gsag.pack(); 426 | gsag.setVisible(true); 427 | } 428 | 429 | } 430 | 431 | 432 | 433 | 434 | 435 | } 436 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuSearchScollege.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | 8 | /** 9 | * 学生信息查询模块 10 | * 根据学生的学院查询学生信息 11 | */ 12 | public class StuSearchScollege extends JFrame implements ActionListener{ 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | Container contentPane; 18 | //框架的大小 19 | 20 | Dimension faceSize = new Dimension(300, 100); 21 | JLabel jLabel1 = new JLabel(); 22 | JTextField sCollege = new JTextField(8); 23 | JButton searchInfo = new JButton(); 24 | 25 | public StuSearchScollege() { 26 | //设置标题 27 | this.setTitle("按学院查询"); 28 | this.setResizable(false); 29 | 30 | try { 31 | Init(); 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | //设置运行位置,使对话框居中 37 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 38 | this.setLocation( (int) (screenSize.width - 400) / 2 , 39 | (int) (screenSize.height - 300) / 2 + 45); 40 | } 41 | 42 | private void Init() throws Exception { 43 | this.setSize(faceSize); 44 | contentPane = this.getContentPane(); 45 | contentPane.setLayout(new FlowLayout()); 46 | 47 | jLabel1.setText("请输入学院名称: "); 48 | jLabel1.setFont(new Font("Dialog",0,12)); 49 | contentPane.add(jLabel1); 50 | 51 | sCollege.setText(null); 52 | sCollege.setFont(new Font("Dialog",0,12)); 53 | contentPane.add(sCollege); 54 | 55 | searchInfo.setText("确定"); 56 | searchInfo.setFont(new Font("Dialog",0,12)); 57 | contentPane.add(searchInfo); 58 | 59 | searchInfo.addActionListener(this); 60 | } 61 | 62 | /** 63 | * 事件处理 64 | */ 65 | public void actionPerformed(ActionEvent e) { 66 | Object obj = e.getSource(); 67 | if (obj == searchInfo) { //查询 68 | ResultStudent rS = new ResultStudent("scollege",sCollege.getText()); 69 | this.dispose(); 70 | } 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuSearchSmajor.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 学生信息查询模块 9 | * 根据学生的专业查询学生信息 10 | */ 11 | public class StuSearchSmajor extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | //框架的大小 18 | Dimension faceSize = new Dimension(300, 100); 19 | JLabel jLabel1 = new JLabel(); 20 | JTextField sMajor = new JTextField(8); 21 | JButton searchInfo = new JButton(); 22 | 23 | public StuSearchSmajor() { 24 | //设置标题 25 | this.setTitle("按专业查询"); 26 | this.setResizable(false); 27 | 28 | try { 29 | Init(); 30 | } 31 | catch (Exception e) { 32 | } 33 | //设置运行位置,使对话框居中 34 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 35 | this.setLocation( (int) (screenSize.width - 400) / 2 , 36 | (int) (screenSize.height - 300) / 2 + 45); 37 | } 38 | 39 | private void Init() throws Exception { 40 | this.setSize(faceSize); 41 | contentPane = this.getContentPane(); 42 | contentPane.setLayout(new FlowLayout()); 43 | 44 | jLabel1.setText("请输入专业名称: "); 45 | jLabel1.setFont(new Font("Dialog",0,12)); 46 | contentPane.add(jLabel1); 47 | 48 | sMajor.setText(null); 49 | sMajor.setFont(new Font("Dialog",0,12)); 50 | contentPane.add(sMajor); 51 | 52 | searchInfo.setText("确定"); 53 | searchInfo.setFont(new Font("Dialog",0,12)); 54 | contentPane.add(searchInfo); 55 | 56 | searchInfo.addActionListener(this); 57 | } 58 | 59 | /** 60 | * 事件处理 61 | */ 62 | public void actionPerformed(ActionEvent e) { 63 | Object obj = e.getSource(); 64 | if (obj == searchInfo) { //查询 65 | ResultStudent rS = new ResultStudent("smajor",sMajor.getText()); 66 | this.dispose(); 67 | } 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuSearchSname.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 学生信息查询模块 9 | * 根据学生的姓名查询学生信息 10 | */ 11 | public class StuSearchSname extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | //框架的大小 18 | Dimension faceSize = new Dimension(300, 100); 19 | JLabel jLabel1 = new JLabel(); 20 | JTextField sName = new JTextField(8); 21 | JButton searchInfo = new JButton(); 22 | 23 | public StuSearchSname() { 24 | //设置标题 25 | this.setTitle("按学姓名查询"); 26 | this.setResizable(false); 27 | 28 | 29 | try { 30 | Init(); 31 | } 32 | catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | //设置运行位置,使对话框居中 36 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 37 | this.setLocation( (int) (screenSize.width - 400) / 2 , 38 | (int) (screenSize.height - 300) / 2 + 45); 39 | } 40 | 41 | private void Init() throws Exception { 42 | this.setSize(faceSize); 43 | contentPane = this.getContentPane(); 44 | contentPane.setLayout(new FlowLayout()); 45 | 46 | jLabel1.setText("请输入学生姓名: "); 47 | jLabel1.setFont(new Font("Dialog",0,12)); 48 | contentPane.add(jLabel1); 49 | 50 | sName.setText(null); 51 | sName.setFont(new Font("Dialog",0,12)); 52 | contentPane.add(sName); 53 | 54 | searchInfo.setText("确定"); 55 | searchInfo.setFont(new Font("Dialog",0,12)); 56 | contentPane.add(searchInfo); 57 | 58 | searchInfo.addActionListener(this); 59 | } 60 | 61 | /** 62 | * 事件处理 63 | */ 64 | public void actionPerformed(ActionEvent e) { 65 | Object obj = e.getSource(); 66 | if (obj == searchInfo) { //查询 67 | ResultStudent rS = new ResultStudent("sname",sName.getText()); 68 | this.dispose(); 69 | } 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuSearchSnum.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 学生信息查询模块 9 | * 根据学生的学号查询学生信息 10 | */ 11 | public class StuSearchSnum extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | //框架的大小 18 | Dimension faceSize = new Dimension(300, 100); 19 | JLabel jLabel1 = new JLabel(); 20 | JLabel jLabel2 = new JLabel(); 21 | JTextField sFrom = new JTextField(4); 22 | JTextField sTo = new JTextField(4); 23 | JButton searchInfo = new JButton(); 24 | 25 | public StuSearchSnum() { 26 | //设置标题 27 | this.setTitle("按学号查询"); 28 | this.setResizable(false); 29 | 30 | 31 | try { 32 | Init(); 33 | } 34 | catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | //设置运行位置,使对话框居中 38 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 39 | this.setLocation( (int) (screenSize.width - 400) / 2 , 40 | (int) (screenSize.height - 300) / 2 + 45); 41 | } 42 | 43 | private void Init() throws Exception { 44 | this.setSize(faceSize); 45 | contentPane = this.getContentPane(); 46 | contentPane.setLayout(new FlowLayout()); 47 | 48 | jLabel1.setText("请输入学号范围: 从"); 49 | jLabel1.setFont(new Font("Dialog",0,12)); 50 | contentPane.add(jLabel1); 51 | 52 | sFrom.setText(null); 53 | sFrom.setFont(new Font("Dialog",0,12)); 54 | contentPane.add(sFrom); 55 | 56 | jLabel2.setText(" 到 "); 57 | jLabel2.setFont(new Font("Dialog",0,12)); 58 | contentPane.add(jLabel2); 59 | 60 | sTo.setText(null); 61 | sTo.setFont(new Font("Dialog",0,12)); 62 | contentPane.add(sTo); 63 | 64 | searchInfo.setText("确定"); 65 | searchInfo.setFont(new Font("Dialog",0,12)); 66 | contentPane.add(searchInfo); 67 | 68 | searchInfo.addActionListener(this); 69 | } 70 | 71 | /** 72 | * 事件处理 73 | */ 74 | public void actionPerformed(ActionEvent e) { 75 | Object obj = e.getSource(); 76 | if (obj == searchInfo) { //查询 77 | ResultStudent rS = new ResultStudent("snum",sFrom.getText(),sTo.getText()); 78 | this.dispose(); 79 | } 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/学生信息管理系统/StuSearchSsex.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | 7 | /** 8 | * 学生信息查询模块 9 | * 根据学生的性别查询学生信息 10 | */ 11 | public class StuSearchSsex extends JFrame implements ActionListener{ 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | Container contentPane; 17 | String[] s = {"男","女"}; 18 | //框架的大小 19 | Dimension faceSize = new Dimension(300, 100); 20 | JLabel jLabel1 = new JLabel(); 21 | JComboBox selectSsex = new JComboBox(s); 22 | JButton searchInfo = new JButton(); 23 | 24 | public StuSearchSsex() { 25 | //设置标题 26 | this.setTitle("按性别查询"); 27 | this.setResizable(false); 28 | 29 | 30 | try { 31 | Init(); 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | //设置运行位置,使对话框居中 37 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 38 | this.setLocation( (int) (screenSize.width - 400) / 2 , 39 | (int) (screenSize.height - 300) / 2 + 45); 40 | } 41 | 42 | private void Init() throws Exception { 43 | this.setSize(faceSize); 44 | contentPane = this.getContentPane(); 45 | contentPane.setLayout(new FlowLayout()); 46 | 47 | jLabel1.setText("请选择学生性别:"); 48 | jLabel1.setFont(new Font("Dialog",0,12)); 49 | contentPane.add(jLabel1); 50 | 51 | selectSsex.setEditable(false); 52 | selectSsex.setSelectedItem(null); 53 | selectSsex.setFont(new Font("Dialog",0,12)); 54 | contentPane.add(selectSsex); 55 | 56 | searchInfo.setText("查询"); 57 | searchInfo.setFont(new Font("Dialog",0,12)); 58 | contentPane.add(searchInfo); 59 | 60 | searchInfo.addActionListener(this); 61 | } 62 | 63 | /** 64 | * 事件处理 65 | */ 66 | public void actionPerformed(ActionEvent e) { 67 | Object obj = e.getSource(); 68 | if (obj == searchInfo) { //退出 69 | ResultStudent rS = new ResultStudent("ssex",(String)selectSsex.getSelectedItem()); 70 | this.dispose(); 71 | } 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/学生信息管理系统/csBean.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import java.util.*; 4 | import java.sql.*; 5 | import javax.swing.*; 6 | 7 | /** 8 | * 成绩选课方面的类 9 | */ 10 | public class csBean { 11 | String sql; 12 | ResultSet rs; 13 | Vector tempvector=new Vector(1,1); 14 | 15 | String cNum; 16 | String sNum; 17 | float grade; 18 | 19 | int colNum; 20 | 21 | /** 22 | * 添加学生的选课信息 23 | */ 24 | public void csAdd(String cnum, String snum){ 25 | 26 | Database DB = new Database(); 27 | 28 | this.cNum = cnum; 29 | this.sNum = snum; 30 | //Integer.parseInt(String)就是将String字符类型数据转换为Integer整型数据。 31 | //Integer.parseInt(String)遇到一些不能被转换为整型的字符时,会抛出异常。 32 | 33 | sql = "insert into sc(cnum,snum) values ("+Integer.parseInt(cNum)+","+Integer.parseInt(sNum)+")"; 34 | try{ 35 | DB.OpenConn(); 36 | DB.executeUpdate(sql); 37 | JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!"); 38 | 39 | } 40 | catch(Exception e){ 41 | JOptionPane.showMessageDialog(null, "保存失败", "错误", JOptionPane.ERROR_MESSAGE); 42 | } 43 | finally { 44 | DB.closeStmt(); 45 | DB.closeConn(); 46 | } 47 | } 48 | 49 | /** 50 | * 修改学生的选课成绩 51 | */ 52 | public void csModify(String cnum, String snum, String grade){ 53 | Database DB = new Database(); 54 | this.cNum = cnum; 55 | this.sNum = snum; 56 | 57 | try{ 58 | this.grade = Float.parseFloat(grade); 59 | } 60 | catch(Exception e){ 61 | JOptionPane.showMessageDialog(null, "成绩输入错误", "错误", JOptionPane.ERROR_MESSAGE); 62 | return; 63 | } 64 | 65 | sql = "update sc set grade = "+grade+" where snum = "+Integer.parseInt(sNum)+" and cnum = "+Integer.parseInt(cNum)+" "; 66 | try{ 67 | DB.OpenConn(); 68 | DB.executeUpdate(sql); 69 | JOptionPane.showMessageDialog(null,"成功登记成绩!"); 70 | } 71 | catch(Exception e){ 72 | System.out.println(e); 73 | JOptionPane.showMessageDialog(null, "登记失败", "错误", JOptionPane.ERROR_MESSAGE); 74 | } 75 | finally { 76 | DB.closeStmt(); 77 | DB.closeConn(); 78 | } 79 | } 80 | 81 | /** 82 | * 删除学生的选课成绩 83 | */ 84 | public void csdel(String cnum, String snum){ 85 | Database DB = new Database(); 86 | this.cNum = cnum; 87 | this.sNum = snum; 88 | 89 | 90 | 91 | sql = "delete from sc where snum = "+Integer.parseInt(sNum)+" and cnum = "+Integer.parseInt(cNum)+" "; 92 | try{ 93 | DB.OpenConn(); 94 | DB.executeUpdate(sql); 95 | JOptionPane.showMessageDialog(null,"成功删除成绩!"); 96 | } 97 | catch(Exception e){ 98 | System.out.println(e); 99 | JOptionPane.showMessageDialog(null, "删除失败", "错误", JOptionPane.ERROR_MESSAGE); 100 | } 101 | finally { 102 | DB.closeStmt(); 103 | DB.closeConn(); 104 | } 105 | } 106 | 107 | /** 108 | * 根据学号搜索其所选的课程名称 109 | */ 110 | public String[] cNameSearch(String snum){ 111 | Database DB = new Database(); 112 | this.sNum = snum; 113 | 114 | sql = "select * from sc,course where sc.snum = "+Integer.parseInt(sNum)+" and sc.cnum = course.cnum"; 115 | String[] cn = null; 116 | int row = 0; 117 | int i = 0; 118 | 119 | try{ 120 | DB.OpenConn(); 121 | rs = DB.executeQuery(sql); 122 | if(rs.last()){ 123 | row = rs.getRow(); 124 | } 125 | if(row == 0){ 126 | cn = null; 127 | } 128 | else{ 129 | cn = new String[row]; 130 | rs.first(); 131 | rs.previous(); 132 | while(rs.next()){ 133 | cn[i] = rs.getString(5); 134 | i++; 135 | } 136 | } 137 | } 138 | catch(Exception e){ 139 | } 140 | finally { 141 | DB.closeStmt(); 142 | DB.closeConn(); 143 | } 144 | return cn; 145 | } 146 | 147 | /** 148 | * 成绩信息综合查询 149 | */ 150 | public String[][] csAllSearch(String snum, int colnum){ 151 | this.sNum = snum; 152 | this.colNum = colnum; 153 | 154 | Database DB = new Database(); 155 | String[][] cn = null; 156 | int row = 0; 157 | int i = 0; 158 | sql = "select * from sc,course,student where sc.snum = "+Integer.parseInt(sNum)+" and sc.cnum = course.cnum and sc.snum = student.snum"; 159 | try{ 160 | DB.OpenConn(); 161 | rs = DB.executeQuery(sql); 162 | 163 | if(rs.last()){ 164 | row = rs.getRow(); 165 | } 166 | if(row == 0){ 167 | cn = null; 168 | } 169 | else{ 170 | cn = new String[row][colNum]; 171 | rs.first(); 172 | rs.previous(); 173 | while(rs.next()){ 174 | cn[i][0] = rs.getString(1); 175 | cn[i][1] = rs.getString(11); 176 | cn[i][2] = rs.getString(2); 177 | cn[i][3] = rs.getString(5); 178 | cn[i][4] = rs.getString(3); 179 | i++; 180 | } 181 | } 182 | } 183 | catch(Exception e){ 184 | } 185 | finally { 186 | DB.closeStmt(); 187 | DB.closeConn(); 188 | } 189 | return cn; 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /src/学生信息管理系统/login.java: -------------------------------------------------------------------------------- 1 | package 学生信息管理系统; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.awt.event.KeyAdapter; 8 | import java.awt.event.KeyEvent; 9 | 10 | 11 | 12 | public class login extends javax.swing.JFrame { 13 | public login() { 14 | init(); 15 | } 16 | //初始化login组件 17 | private void init() { 18 | JPanel jPanel1 = new JPanel();//面板1,用于放用户名,输入框 19 | JPanel jPanel2 = new JPanel();//面板2,用于放密码,输入框 20 | JPanel jPanel3 = new JPanel();//面板3,用于放ok exit 按钮 21 | JLabel jLabel1 = new JLabel("用户名:");//标签1(用户名),嵌在jPane1 22 | JLabel jLabel2 = new JLabel("密 码: ");//标签2(密码),嵌在jPane2 23 | JTextField Username = new JTextField(10);//用户名输入框,嵌在jPane1 24 | JPasswordField Password = new JPasswordField(10);//密码输入框,嵌在jPane2 25 | JButton Login = new JButton("登录");//登录按钮,嵌在jPane4 26 | JButton Exit = new JButton("退出");//退出按钮,嵌在jPane4 27 | 28 | jLabel1.setFont(new java.awt.Font("微软雅黑", Font.PLAIN, 14)); 29 | jLabel2.setFont(new java.awt.Font("微软雅黑", Font.PLAIN, 14)); 30 | Login.setFont(new java.awt.Font("微软雅黑", Font.PLAIN, 14)); 31 | Exit.setFont(new java.awt.Font("微软雅黑",Font.PLAIN, 14)); 32 | Username.setToolTipText("在此处输入用户名"); 33 | Password.setToolTipText("在此处输入密码"); 34 | 35 | 36 | //布局管理器(GridLayout) 37 | this.setLayout(new GridLayout(4, 3)); 38 | jPanel1.add(jLabel1); 39 | jPanel1.add(Username); 40 | jPanel2.add(jLabel2); 41 | jPanel2.add(Password); 42 | 43 | 44 | 45 | jPanel3.add(Login); 46 | jPanel3.add(Exit); 47 | 48 | this.add(jPanel1); 49 | this.add(jPanel2); 50 | this.add(jPanel3); 51 | 52 | 53 | this.setTitle("用户登录"); 54 | this.setSize(400, 300); 55 | this.setLocationRelativeTo(null); 56 | this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 57 | this.setVisible(true); 58 | this.setResizable(false); 59 | 60 | //Exit动作 61 | 62 | Exit.addActionListener(e ->System.exit(0)); 63 | 64 | //密码框回车等于点击登录 65 | Password.addKeyListener(new KeyAdapter() { 66 | @Override 67 | public void keyTyped(KeyEvent e) { 68 | super.keyTyped(e); 69 | if(e.getKeyChar()=='\n'){ 70 | Login.doClick(); 71 | } 72 | } 73 | }); 74 | //Login动作 75 | 76 | Login.addActionListener(new ActionListener() { 77 | @Override 78 | 79 | public void actionPerformed(ActionEvent e) { 80 | String user = Username.getText().trim(); 81 | 82 | String pass = Password.getText().trim(); 83 | String un1 = "admin"; 84 | String pw1 = "admin"; 85 | 86 | 87 | if (user.length() == 0 && pass.length() == 0) { 88 | JOptionPane.showMessageDialog(null, "用户名和密码不能为空!", "提示消息!", JOptionPane.WARNING_MESSAGE); 89 | } else if (user.length() == 0) { 90 | JOptionPane.showMessageDialog(null, "用户名不能为空!", "提示消息!", JOptionPane.WARNING_MESSAGE); 91 | } else if (pass.length() == 0) { 92 | JOptionPane.showMessageDialog(null, "密码不能为空!", "提示消息!", JOptionPane.WARNING_MESSAGE); 93 | } else if(user.equals(un1)&pass.equals(pw1)){ 94 | setVisible(false); 95 | new StuMain().setVisible(true);; 96 | }else if(!user.equals(un1)||!pass.equals(pw1)){ 97 | JOptionPane.showMessageDialog(null, "用户名或者密码错误!", "提示消息!", JOptionPane.WARNING_MESSAGE); 98 | Username.setText(""); 99 | Password.setText(""); 100 | } 101 | 102 | } 103 | }); 104 | } 105 | } 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /打包好的jar程序/学生信息管理系统.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1065448858/StudentManager/2b456b4f78edac5de8cb94fa86d12dc932d3ceff/打包好的jar程序/学生信息管理系统.jar -------------------------------------------------------------------------------- /打包好的jar程序/学生信息管理系统_lib/mysql-connector-java-5.1.45-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1065448858/StudentManager/2b456b4f78edac5de8cb94fa86d12dc932d3ceff/打包好的jar程序/学生信息管理系统_lib/mysql-connector-java-5.1.45-bin.jar -------------------------------------------------------------------------------- /打包好的jar程序/运行说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1065448858/StudentManager/2b456b4f78edac5de8cb94fa86d12dc932d3ceff/打包好的jar程序/运行说明.txt --------------------------------------------------------------------------------