📄 studentinterface.java~46~
字号:
package Chapter1;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class StudentInterface extends JFrame implements ActionListener{ public static final int WIDTH=400; public static final int HEIGHT=400; JLabel jLabel1 = new JLabel(); public StudentInterface() { setSize(WIDTH,HEIGHT); setTitle("学生信息管理系统学生用户界面"); Container contentPane=getContentPane(); contentPane.setBackground(Color.green); JMenu m1=new JMenu("信息录入"); JMenu m2=new JMenu("信息查询"); JMenu m3=new JMenu("查看排名"); JMenu m4=new JMenu("系统"); JMenu m5=new JMenu("打印"); JMenu m6=new JMenu("帮助"); JMenu m7=new JMenu("已选课删除"); JMenuItem m11=new JMenuItem("选课信息录入"); m11.addActionListener(this); m1.add(m11); //完成第一个菜单的定义 JMenuItem m21=new JMenuItem("基本信息查询"); JMenuItem m22=new JMenuItem("课程信息查询"); JMenuItem m23=new JMenuItem("选课信息查询"); JMenuItem m24=new JMenuItem("成绩查询"); m21.addActionListener(this); m22.addActionListener(this); m23.addActionListener(this); m24.addActionListener(this); m2.add(m21); m2.add(m22); m2.add(m23); m2.add(m24); //完成第二个菜单的定义 JMenuItem m31=new JMenuItem("按单科成绩"); JMenuItem m32=new JMenuItem("按平均分"); m31.addActionListener(this); m32.addActionListener(this); m3.add(m31); m3.add(m32); //完成第三个菜单的定义 JMenuItem m40=new JMenuItem("查询密码"); JMenuItem m41=new JMenuItem("修改密码"); JMenuItem m42=new JMenuItem("退出系统"); JMenuItem m43=new JMenuItem("重新登录"); m40.addActionListener(this); m41.addActionListener(this); m42.addActionListener(this); m43.addActionListener(this); m4.add(m40); m4.add(m41); m4.add(m42); m4.add(m43); //完成第四个菜单的定义 JMenuItem m51=new JMenuItem("开始打印"); m51.addActionListener(this); m5.add(m51); //完成第五个菜单的定义 JMenuItem m61=new JMenuItem("使用说明"); JMenuItem m62=new JMenuItem("版本信息"); m61.addActionListener(this); m62.addActionListener(this); m6.add(m61); m6.add(m62); JMenuItem m71=new JMenuItem("已选课删除"); m71.addActionListener(this); m7.add(m71); JMenuBar mBar=new JMenuBar(); mBar.add(m1); mBar.add(m2); mBar.add(m7); mBar.add(m3); mBar.add(m4); mBar.add(m5); mBar.add(m6); setJMenuBar(mBar); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public void actionPerformed(ActionEvent e) { String cmd=e.getActionCommand(); if(cmd.equals("选课信息录入")) { this.setVisible(false); ClassesChoiceInput n = new ClassesChoiceInput(); n.setVisible(true); } else if(cmd.equals("基本信息查询")) { this.setVisible(false); BasicInformationQuery n = new BasicInformationQuery(); n.setVisible(true); } else if(cmd.equals("课程信息查询")) { this.setVisible(false); ClassesInformationQuery n = new ClassesInformationQuery(); n.setVisible(true); } else if(cmd.equals("选课信息查询")) { this.setVisible(false); ClassesChoiceQuery n = new ClassesChoiceQuery(); n.setVisible(true); } else if(cmd.equals("成绩查询")) { this.setVisible(false); ScoresQuery n=new ScoresQuery(); n.setVisible(true);// String [] columnNames={"学号","姓名","高等数学","JAVA","计算机组成原理","个体软件过程","大学英语","军事理论","中华民族历史与精神","传统文学修养","体育","线性代数(续)","中外音乐欣赏","行政管理","总成绩","GPA成绩","平均分","排名","备注"};// Object [][] rowData=new Object[10][19];// try// {// String url="jdbc:odbc:MySecondAccess";// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");// Connection con=DriverManager.getConnection(url,"","");// Statement stmt=con.createStatement();// String SQLOrder="SELECT * FROM Scores ";// ResultSet resultSet=stmt.executeQuery(SQLOrder);//// int count=0;// while (resultSet.next())// {// rowData [count][0] = resultSet.getString(1);// rowData [count][1] = resultSet.getString(2);// rowData [count][2] = Integer.toString(resultSet.getInt("高等数学"));// rowData [count][3] = Integer.toString(resultSet.getInt("JAVA"));// rowData [count][4] = Integer.toString(resultSet.getInt("计算机组成原理"));// rowData [count][5] = Integer.toString(resultSet.getInt("个体软件过程"));// rowData [count][6] = Integer.toString(resultSet.getInt("大学英语"));// rowData [count][7] = Integer.toString(resultSet.getInt("军事理论"));// rowData [count][8] = Integer.toString(resultSet.getInt("中华民族历史与精神"));// rowData [count][9] = Integer.toString(resultSet.getInt("传统文学修养"));// rowData [count][10]= Integer.toString(resultSet.getInt("体育"));// rowData [count][11]= Integer.toString(resultSet.getInt("线性代数(续)"));// rowData [count][12]= Integer.toString(resultSet.getInt("中外音乐欣赏"));// rowData [count][13]= Integer.toString(resultSet.getInt("行政管理"));// rowData [count][14]= Integer.toString(resultSet.getInt("总成绩"));// rowData [count][15]= Integer.toString(resultSet.getInt("GPA成绩"));// rowData [count][16]= Integer.toString(resultSet.getInt("平均分"));// rowData [count][17]= Integer.toString(resultSet.getInt("排名"));// rowData [count][18]= resultSet.getString("备注");// count++;// }// stmt.close();// con.close();// }// catch(Exception ex)// {// System.out.println(ex.getStackTrace());// System.out.println(ex.getMessage());// }//// Container container=getContentPane(); //获取窗口容器// JTable table=new JTable(rowData,columnNames); //实例化表格// table.getColumn("姓名").setMaxWidth(35); //设置行宽// container.add(new JScrollPane(table),BorderLayout.CENTER); //增加组件// setSize(1000,450);// setVisible(true); //设置窗口可视// // setDefaultCloseDperation(JFrame.EXIT_ON_CLOSE); } else if(cmd.equals("已选课删除")) { this.setVisible(false); String name=JOptionPane.showInputDialog("请输入您要删除的课程的课程名!"); try { String url="jdbc:odbc:MySecondAccess"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"",""); Statement stmt=con.createStatement(); String SQLOrder="UPDATE ClassesChoicesInformation SET '"+name+"'=0 WHERE 学号='"+Login.ID+"'"; stmt.executeUpdate(SQLOrder); stmt.close(); con.close(); JOptionPane.showMessageDialog(null,"已选课程删除成功!","提示信息",JOptionPane.INFORMATION_MESSAGE); } catch(Exception ex) { System.out.println(ex.getStackTrace()); System.out.println(ex.getMessage()); } } else if(cmd.equals("修改密码")) { String formerPassword=JOptionPane.showInputDialog("请输入您的旧密码!"); if(!formerPassword.equals(Login.password)) { JOptionPane.showMessageDialog(null,"您输入的旧密码不正确!请重新输入!","提示信息",JOptionPane.WARNING_MESSAGE); formerPassword=JOptionPane.showInputDialog("请输入您的旧密码!"); } else { String newPassword1=JOptionPane.showInputDialog("请输入您的新密码!"); String newPassword2=JOptionPane.showInputDialog("请确认新密码!"); if(formerPassword.equals(Login.password)&&newPassword1.equals(newPassword2)) { try { String url="jdbc:odbc:MySecondAccess"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"",""); Statement stmt=con.createStatement(); String SQLOrder="UPDATE StudentsInformation SET 密码='"+newPassword1+"' WHERE 帐号='"+Login.ID+"'"; stmt.executeUpdate(SQLOrder); stmt.close(); con.close(); } catch(Exception ex) { System.out.println(ex.getStackTrace()); System.out.println(ex.getMessage()); } } } } else if(cmd.equals("查询密码")) { JOptionPane.showMessageDialog(null,"您的密码是"+Login.password,"查询密码",JOptionPane.INFORMATION_MESSAGE); } else if(cmd.equals("退出系统")) { System.exit(0); } else if(cmd.equals("重新登录")) { this.setVisible(false); Login n=new Login(); n.setVisible(true); } else if(cmd.equals("开始打印")) { JOptionPane.showMessageDialog(null,"对不起,您还没有配置打印机!","张呈刚提醒您......",JOptionPane.WARNING_MESSAGE); } else if(cmd.equals("使用说明")) { this.setVisible(false); Instructions n=new Instructions(); n.setVisible(true); } else if(cmd.equals("版本信息")) { JOptionPane.showMessageDialog(null,"学生信息综合管理系统,开发者:张呈刚(05软件3班)","版本信息",JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] args) { StudentInterface n=new StudentInterface(); n.setVisible(true); } private void jbInit() throws Exception { try { String url="jdbc:odbc:MySecondAccess"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"",""); Statement stmt=con.createStatement(); String SQLOrder="SELECT 姓名 FROM StudentsInformation WHERE 帐号='"+Login.jTextField1.getText()+"'"; ResultSet resultSet=stmt.executeQuery(SQLOrder); while(resultSet.next()) { String name=resultSet.getString("姓名"); jLabel1.setText(Login.jTextField1.getText()+" "+name+",你好!欢迎登录学生信息管理系统!"); } stmt.close(); con.close(); } catch(Exception ex) { System.out.println(ex.getStackTrace()); System.out.println(ex.getMessage()); } jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); jLabel1.setForeground(new Color(125, 98, 255)); jLabel1.setBounds(new Rectangle(1, 100, 400, 121)); this.getContentPane().setLayout(null); this.setFont(new java.awt.Font("Dialog", 1, 16)); this.setForeground(new Color(255, 98, 98)); this.getContentPane().add(jLabel1, null); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -