表8 reward_levels奖励等级代码表
表9 punish_levels处罚等级代码表
表10 studentdlb学生账号密码登录表
表11 teacherdlb老师账号密码登录表
4.1、学生和教务办老师的账号密码登陆界面
学生和教务办老师的账号密码登陆界面请见如图3-1学生和教务办老师的账号密码登陆界面。这个界面是进入学生信息管理系统的钥匙并且设置了教务办老师和学生两个权限,为了实现不同权限的登录功能,所以在数据库中设计了学生账号密码登录表和老师账号密码登录表两个表格,然后用户可以选择自己的身份权限输入自己的账号密码进行登录,然后系统通过连接数据库的两个表格去和用户输入的账号密码去相应匹配,只有匹配成功之后才会出现不同的用户主界面,然后才可以进行数据操作。(用户名的填写格式界面文本框有提示)
实现学生和教务办老师的账号密码登陆界面的全部代码:
package xr06; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; import javax.swing.*; import xr06.DbProcess; public class Student_management_login_system extends JFrame implements ActionListener { JButton jb1,jb2,jb3=null; JRadioButton jrb1,jrb2=null; JPanel jp0,jp1,jp2,jp3,jp4=null; JTextField jtf=null; JLabel jlb0,jlb1,jlb2,jlb3=null; JPasswordField jpf=null; ButtonGroup bg=null; private static DbProcess dbProcess; public static void main(String[] args) { Student_management_login_system smls=new Student_management_login_system(); } public Student_management_login_system() { setIconImage(Toolkit.getDefaultToolkit().getImage("G:\\timg-1.jpg"));//图片可以自己选择换 jb1=new JButton("登录 (login)"); jb1.setBounds(32, 5, 150, 27); jb1.setBackground(Color.ORANGE); jb2=new JButton("重置 (resetting)"); jb2.setBounds(196, 5, 204, 27); jb2.setBackground(Color.ORANGE); jb3=new JButton("退出 (exit)"); jb3.setBounds(414, 5, 150, 27); jb3.setForeground(Color.BLACK); jb3.setBackground(Color.ORANGE); jb1.addActionListener(this); jb2.addActionListener(this); jb3.addActionListener(this); jrb1=new JRadioButton("教务办老师 (teacher)"); jrb1.setFont(new Font("宋体", Font.BOLD, 15)); jrb1.setBounds(216, 30, 201, 27); jrb1.setBackground(new Color(255, 255, 153)); jrb2=new JRadioButton("学生 (student)"); jrb2.setFont(new Font("宋体", Font.BOLD, 15)); jrb2.setBounds(423, 30, 163, 27); jrb2.setBackground(new Color(255, 255, 153)); bg=new ButtonGroup(); bg.add(jrb1); bg.add(jrb2); jrb2.setSelected(true); jp0=new JPanel(); jp0.setBounds(0, 0, 602, 100); jp0.setBackground(new Color(255, 255, 153)); jp1=new JPanel(); jp1.setBounds(0, 99, 602, 55); jp1.setBackground(new Color(255, 255, 153)); jp2=new JPanel(); jp2.setBounds(0, 152, 602, 70); jp2.setBackground(new Color(255, 255, 153)); jp3=new JPanel(); jp3.setBounds(0, 221, 602, 86); jp3.setBackground(new Color(255, 255, 153)); jp4=new JPanel(); jp4.setBounds(0, 307, 602, 93); jp4.setBackground(new Color(255, 255, 153)); jlb0=new JLabel("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF"); jlb0.setFont(new Font("方正舒体", Font.BOLD, 40)); jlb0.setBounds(129, 36, 351, 51); jlb1=new JLabel("用户名 (user name):"); jlb1.setFont(new Font("宋体", Font.BOLD, 18)); jlb1.setBounds(54, 25, 236, 18); jlb2=new JLabel("\u5BC6 \u7801 (pass-word)\uFF1A"); jlb2.setFont(new Font("宋体", Font.BOLD, 18)); jlb2.setBounds(54, 35, 227, 18); jlb3=new JLabel("\u8EAB \u4EFD (Identity)\uFF1A"); jlb3.setFont(new Font("宋体", Font.BOLD, 15)); jlb3.setBounds(29, 26, 201, 34); jtf=new JTextField(15); jtf.setBounds(253, 24, 281, 24); jpf=new JPasswordField(15); jpf.setBounds(253, 34, 281, 24); jtf.addFocusListener(new JTextFieldHintListener("请输入学号/教职工号", jtf)); jp0.setLayout(null); jp0.add(jlb0); jp1.setLayout(null); jp1.add(jlb1); jp1.add(jtf); jp2.setLayout(null); jp2.add(jlb2); jp2.add(jpf); jp3.setLayout(null); jp3.add(jlb3); //添加标签 jp3.add(jrb1); jp3.add(jrb2); jp4.setLayout(null); jp4.add(jb1); //添加按钮 jp4.add(jb2); jp4.add(jb3); getContentPane().setLayout(null); getContentPane().add(jp0); getContentPane().add(jp1); getContentPane().add(jp2); getContentPane().add(jp3); getContentPane().add(jp4); this.setTitle("学生信息管理系统 "); this.setSize(605,433); this.setLocation(700, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置当关闭窗口时,保证JVM也退出 this.setVisible(true); this.setResizable(false); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("登录 (login)") && !jtf.getText().isEmpty()&&!jpf.getText().isEmpty()){ System.out.println("actionPerformed(). 登录 (login)"); String jtfQueryField = jtf.getText().trim(); String jpfQueryField = jpf.getText().trim(); queryProcess(jtfQueryField,jpfQueryField); } else if(e.getActionCommand().equals("登录 (login)") && jtf.getText().isEmpty()&&!jpf.getText().isEmpty()){ JOptionPane.showMessageDialog(null,"请输入用户名!","提示消息",JOptionPane.WARNING_MESSAGE); }//只有用户名没有输入 else if(e.getActionCommand().equals("登录 (login)") && jtf.getText().isEmpty()&& jpf.getText().isEmpty()){ JOptionPane.showMessageDialog(null,"请输入用户名和密码!","提示消息",JOptionPane.WARNING_MESSAGE); }//用户名和密码都没有输入 else if(e.getActionCommand().equals("登录 (login)") && !jtf.getText().isEmpty()&&jpf.getText().isEmpty()){ JOptionPane.showMessageDialog(null,"请输入密码!","提示消息",JOptionPane.WARNING_MESSAGE); }//只有密码没有输入 else if(e.getActionCommand().equals("重置 (resetting)")){ jtf.setText(""); jpf.setText(""); } else{ int n=JOptionPane.showConfirmDialog(null,"确定退出系统登陆界面?", "学生信息管理系统",JOptionPane.YES_NO_OPTION); if(n==0) { this.setVisible(false); } } } public void queryProcess(String jtfQueryField,String jpfQueryField) { if(jrb1.isSelected()) { try{ // 建立查询条件 String jtfsql = "select * from teacherdlb where "; jtfsql = jtfsql + "tuserNo"; jtfsql = jtfsql + " = "; jtfsql = jtfsql + "'" + jtfQueryField + "';"; System.out.println("queryProcess(). jtfsql = " + jtfsql); dbProcess = new DbProcess(); dbProcess.connect(); ResultSet jtfrs = dbProcess.executeQuery(jtfsql); jtfrs.next(); System.out.print(jpfQueryField); if(jtfrs.getString("tuserNo").equals(jtfQueryField)&&jtfrs.getString("tpswd").equals(jpfQueryField)) { JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE); dispose(); jtf.setText(""); jpf.setText(""); Teacher t=new Teacher(); //创建新界面 }else { JOptionPane.showMessageDialog(null,"密码错误!请重新输入密码!","提示消息",JOptionPane.WARNING_MESSAGE); jpf.setText(""); } dbProcess.disconnect(); }catch(SQLException sqle){ System.out.println("sqle = " + sqle); JOptionPane.showMessageDialog(null, "用户名或者密码错误!","错误",JOptionPane.ERROR_MESSAGE); }catch(Exception e){ System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "用户名或者密码错误!","错误",JOptionPane.ERROR_MESSAGE); } //连接到教师的方法 页面 } if(jrb2.isSelected()) //学生在登录系统 { try{ // 建立查询条件 String jtfsql = "select * from studentdlb where "; jtfsql = jtfsql + "suserNo"; jtfsql = jtfsql + " = "; jtfsql = jtfsql + "'" + jtfQueryField + "';"; System.out.println("queryProcess(). jtfsql = " + jtfsql); dbProcess = new DbProcess(); dbProcess.connect(); ResultSet jtfrs = dbProcess.executeQuery(jtfsql); jtfrs.next(); System.out.print(jpfQueryField); if(jtfrs.getString("suserNo").equals(jtfQueryField)&&jtfrs.getString("spswd").equals(jpfQueryField)) { JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE); dispose(); jtf.setText(""); jpf.setText(""); Student ui=new Student(); //创建新界面 }else { JOptionPane.showMessageDialog(null,"密码错误!请重新输入密码!","提示消息",JOptionPane.WARNING_MESSAGE); jpf.setText(""); } dbProcess.disconnect(); }catch(SQLException sqle){ System.out.println("sqle = " + sqle); JOptionPane.showMessageDialog(null, "用户名或者密码错误!","错误",JOptionPane.ERROR_MESSAGE); }catch(Exception e){ System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "用户名或者密码错误!","错误",JOptionPane.ERROR_MESSAGE); } //连接到学生的方法 页面 } } }
图3-1学生和教务办老师的账号密码登陆界面
4.2、学生用户主界面
学生用户主界面请见如图3-2学生用户主界面。首先这个界面是在选择学生权限用户登录之后出现的,这个界面可以供用户选择查询各式个人信息以及了解学校学院相关的一些常识或者退出系统(点击相应的按钮,然后会出现相应的功能界面),同时为了使界面更加优化,特别插入了“超越梦想”为主题的图片,希望学生用户能够好好提升自己,为梦想努力奋斗,超越自我,迎来美丽人生。
实现学生用户主界面的全部代码:
package xr06; import java.util.Vector; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Color; import java.awt.Font; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import java.awt.Toolkit; public class Student extends JFrame implements ActionListener { private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { Student ui=new Student(); } /** * Create the frame. */ public Student() { setIconImage(Toolkit.getDefaultToolkit().getImage("G:\\timg-1.jpg"));//插入图片 this.setResizable(false); setTitle("学生信息管理系统"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(700, 320, 579, 409); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JPanel panel = new JPanel(); panel.setBackground(new Color(255, 255, 153)); panel.setBounds(0, 0, 573, 374); contentPane.add(panel); panel.setLayout(null); JLabel lblNewLabel = new JLabel("同学你好!欢迎登陆学生信息管理系统"); lblNewLabel.setFont(new Font("宋体", Font.BOLD, 20)); lblNewLabel.setForeground(new Color(255, 255, 0)); lblNewLabel.setBounds(94, 24, 366, 32); panel.add(lblNewLabel); JButton button_1 = new JButton("个人信息查询"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); Personcx px = new Personcx(); } }); button_1.setBounds(86, 90, 167, 32); panel.add(button_1); JButton button_2 = new JButton("个人奖励记录"); button_2.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { dispose(); Personjl xj = new Personjl(); } }); button_2.setBounds(86, 148, 167, 32); panel.add(button_2); JButton button_3 = new JButton("个人学籍变更记录"); button_3.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { dispose(); Personxj xj = new Personxj(); } }); button_3.setBounds(293, 90, 167, 32); panel.add(button_3); JButton button_4 = new JButton("个人处分记录"); button_4.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { dispose(); Personcf cf = new Personcf(); } }); button_4.setBounds(293, 148, 167, 32); panel.add(button_4); JButton button_5 = new JButton("退出"); button_5.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int n=JOptionPane.showConfirmDialog(null,"确定退出该系统?", "学生信息管理系统",JOptionPane.YES_NO_OPTION); if(n==0) { dispose(); Student_management_login_system sm=new Student_management_login_system(); } } }); button_5.setForeground(Color.RED); button_5.setBounds(293, 206, 167, 32); panel.add(button_5); JLabel label = new JLabel(" 温馨提示:新生个人登陆系统之后请先查看入学须知"); label.setFont(new Font("宋体", Font.PLAIN, 16)); label.setForeground(new Color(153, 255, 51)); label.setBounds(25, 277, 487, 41); panel.add(label); JButton button = new JButton("入学须知"); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { dispose(); Personrx rx = new Personrx(); } }); button.setBounds(86, 206, 167, 32); panel.add(button); JLabel lblNewLabel_1 = new JLabel("New label"); lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\\u8C22\u5112\\Pictures\\Camera Roll\\29755920_1478787143469_1024x1024.jpg")); lblNewLabel_1.setBounds(0, 0, 573, 400); panel.add(lblNewLabel_1); this.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } }
图3-2学生用户主界面
3.3、老师学生账号密码界面
老师学生账号密码界面请见如图3-3老师学生账号密码界面。这个界面的设计同样是专门为教务办用户设计,能通过点击全部查询,查询到系统录入的所有同学和教务办老师的账号密码,这个界面信息显示也采用了多表查询,将学生账号密码登录表、老师账号密码登录表两个表格联合查询;然后也可以通过下拉框选择相应想要选择查询的内容比如老师账号,然后点击查询获取相对应的老师账号密码信息。如果修改了账号和密码点击更新按钮,又确认实施该操作,那么会退出系统返回到原始登录界面,其它按钮的功能同上。
实现老师学生账号密码界面的全部代码:
package xr06; import java.util.Vector; import java.awt.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; import org.omg.CORBA.PUBLIC_MEMBER; import java.awt.color.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.sql.ResultSet; import java.sql.SQLException; public class Studentzh extends JFrame implements ActionListener { // 定义基本信息组件 JLabel jLStudentxjTable = null;// 学生学籍表 JLabel jLSelectQueryField = null;// 选择 JLabel mh = null;// : JLabel teacherzh = null;// 老师账号 JLabel teachermm = null;// 老师密码 JLabel studentzh = null;// 学生账号 JLabel studentmm = null;// 学生密码 JLabel ms = null;// 描述 JLabel dm = null;// 代码 JLabel sm = null;// 说明 /// 定义文本框 JTextField jTFQueryField = null;// 查询字段 JTextField jTFSTz = null;// 老师账号 JTextField jTFSTP = null;// 老师密码 JTextField jTFSSZ = null;// 学生账号 JTextField jTFSSP = null;// 学生密码 JTextField jTFSDES = null;// 描述 JTextField jTFSCode = null;// 代码 JTextField jTFSsm = null;// 说明 // 定义按钮 JButton jb5 = null;// 顶部选择的四个表+1个菜单 JButton jBQuery = null;// 查询 JButton jBQueryAll = null;// 查询所有记录 JButton jBInsert = null;// 插入 JButton jBUpdate = null;// 更新 JButton jBDeleteCurrentRecord = null;// 删除当前记录 JButton jBDeleteAllRecords = null;// 删除所有记录 JButton EXIT = null;// 退出 // 定义其他 JComboBox<String> jCBSelectQueryField = null;// 查询字段 JComboBox<String> jCBsexQueryField = null;// JPanel jP1, jP2, jP3, jP4, jP5, jP6, jP8 = null; JPanel jPTop, jPBottom = null; DefaultTableModel studentTableModel = null; JTable studentJTable = null; JScrollPane studentJScrollPane = null; Vector studentVector = null; Vector titleVector = null; private static DbProcess dbProcess; String SelectQueryFieldStr = "老师账号"; public static void main(String[] args) { Studentzh ss = new Studentzh(); } // ****************************事件判断********************** public Studentzh() { setIconImage(Toolkit.getDefaultToolkit().getImage("G:\\timg-1.jpg")); this.setResizable(false); jLSelectQueryField = new JLabel("选择"); jLSelectQueryField.setBounds(5, 9, 30, 18); mh = new JLabel(" : "); mh.setBounds(192, 9, 24, 18); teacherzh = new JLabel("老师账号:"); teacherzh.setBounds(5, 25, 68, 18); teachermm = new JLabel("老师密码:"); teachermm.setBounds(323, 25, 68, 18); // 文本框创建 jTFQueryField = new JTextField(10);// 查询字段 jTFQueryField.setBounds(214, 6, 106, 24); jTFSTz = new JTextField(15);// 老师账号 jTFSTz.setBounds(79, 18, 215, 24); jTFSTP = new JTextField(15);// 老师密码 jTFSTP.setBounds(395, 18, 215, 24); jBQuery = new JButton("查询选择内容"); jBQuery.setBounds(334, 5, 155, 27); jBQuery.setFont(new Font("宋体", Font.BOLD, 15)); jBQueryAll = new JButton("查询所有记录"); jBQueryAll.setBounds(503, 5, 155, 27); jBQueryAll.setFont(new Font("宋体", Font.BOLD, 15)); jBQuery.addActionListener(this); jBQueryAll.addActionListener(this); // 建立下拉框 jCBSelectQueryField = new JComboBox<String>();// 查询字段 jCBSelectQueryField.setBounds(37, 6, 155, 24); jCBSelectQueryField.addItem("老师账号"); jCBSelectQueryField.addItem("老师密码"); jCBSelectQueryField.addItem("学生账号"); jCBSelectQueryField.addItem("学生密码"); jCBSelectQueryField.addItemListener(new ItemListener() {// 下拉框事件监听 public void itemStateChanged(ItemEvent event) { switch (event.getStateChange()) { case ItemEvent.SELECTED: SelectQueryFieldStr = (String) event.getItem(); System.out.println("选中:" + SelectQueryFieldStr); break; case ItemEvent.DESELECTED: System.out.println("取消选中:" + event.getItem()); break; } } }); studentVector = new Vector(); titleVector = new Vector(); // 定义表头 titleVector.add("老师账号"); titleVector.add("老师密码"); titleVector.add("学生账号"); titleVector.add("学生密码"); studentJTable = new JTable(studentVector, titleVector); studentJTable.setPreferredScrollableViewportSize(new Dimension(400, 160)); studentJScrollPane = new JScrollPane(studentJTable); studentJScrollPane.setBounds(0, 0, 480, 172); // 分别设置水平和垂直滚动条自动出现 studentJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); studentJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); // 为表格添加监听器 studentJTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置 System.out.println("mouseClicked(). row = " + row); Vector v = new Vector(); v = (Vector) studentVector.get(row); jTFSTz.setText((String) v.get(0));// 老师账号 jTFSTP.setText((String) v.get(1));// 老师密码 jTFSSZ.setText((String) v.get(2));// 学生账号 jTFSSP.setText((String) v.get(3));// 学生密码 } }); jP1 = new JPanel(); jP1.setBounds(356, 17, 8, 2); jP3 = new JPanel(); jP3.setBounds(98, 55, 480, 172); jP3.setBackground(new Color(204, 51, 0)); jP4 = new JPanel(); jP4.setBackground(new Color(255, 255, 102)); jP4.setBounds(0, 13, 682, 45); jP5 = new JPanel(); jP5.setBackground(new Color(255, 255, 153)); jP5.setBounds(0, 69, 682, 45); jP6 = new JPanel(); jP6.setBackground(new Color(255, 255, 153)); jP6.setBounds(0, 113, 682, 79); jPTop = new JPanel(); jPTop.setBackground(new Color(255, 255, 102)); jPBottom = new JPanel(); jPBottom.setBackground(new Color(255, 255, 51)); jP3.setLayout(null); jP3.add(studentJScrollPane); jP1.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 1)); jP4.setLayout(null); //底部的五部分 // 第四行 jP4.add(jLSelectQueryField);// 文字“选择” jP4.add(jCBSelectQueryField);// 下拉框 jP4.add(mh); jP4.add(jTFQueryField); jP4.add(jBQuery); jP4.add(jBQueryAll); jP4.setPreferredSize(new Dimension(20, 20)); jP5.setLayout(null); // 第五行 jP5.add(teacherzh); jP5.add(jTFSTz); jP5.add(teachermm); jP5.add(jTFSTP); jP5.setPreferredSize(new Dimension(20, 20)); jP6.setLayout(null); studentzh = new JLabel("学生账号:"); studentzh.setBounds(5, 32, 68, 18); jP6.add(studentzh); jTFSSZ = new JTextField(15);// 学生账号 jTFSSZ.setBounds(79, 29, 215, 24); jP6.add(jTFSSZ); studentmm = new JLabel("学生密码:"); studentmm.setBounds(323, 32, 68, 18); jP6.add(studentmm); jP6.setPreferredSize(new Dimension(20, 20)); jPTop.setLayout(null); // 命名组件 jLStudentxjTable = new JLabel("账户密码表"); jLStudentxjTable.setBounds(14, 13, 130, 26); jLStudentxjTable.setFont(new Font("华文新魏", Font.BOLD, 25)); jP2 = new JPanel(); jP2.setBackground(new Color(255, 255, 102)); jP2.setBounds(258, 0, 165, 50); jP2.setLayout(null); jP2.add(jLStudentxjTable); jPTop.add(jP2); // 设置顶部 jPTop.add(jP1); jPTop.add(jP3); jPBottom.setLayout(null); jPBottom.add(jP4); jPBottom.add(jP5); jPBottom.add(jP6); jTFSSP = new JTextField(15); jTFSSP.setBounds(395, 29, 215, 24); jP6.add(jTFSSP); // 设置大局面 getContentPane().add("North", jPTop); JLabel lblNewLabel = new JLabel(" \u6CE8\u610F\u4E8B\u9879\uFF1A\u8D26\u53F7\u5BC6\u7801\u6D89\u53CA\u4F7F\u7528\u8005\u548C\u7BA1\u7406\u8005\u9690\u79C1\uFF0C\u8BF7\u52FF\u6CC4\u9732\u5916\u4F20\uFF01"); lblNewLabel.setBounds(79, 224, 523, 36); jPTop.add(lblNewLabel); lblNewLabel.setForeground(new Color(255, 0, 0)); lblNewLabel.setFont(new Font("华文宋体", Font.BOLD, 17)); getContentPane().add("South", jPBottom); jBInsert = new JButton("插入"); jBInsert.setBounds(10, 205, 80, 27); jPBottom.add(jBInsert); jBInsert.setFont(new Font("宋体", Font.BOLD, 15)); jBUpdate = new JButton("更新"); jBUpdate.setBounds(95, 205, 80, 27); jPBottom.add(jBUpdate); jBUpdate.setFont(new Font("宋体", Font.BOLD, 15)); jBDeleteCurrentRecord = new JButton("删除当前记录"); jBDeleteCurrentRecord.setBounds(189, 205, 155, 27); jPBottom.add(jBDeleteCurrentRecord); jBDeleteCurrentRecord.setFont(new Font("宋体", Font.ITALIC, 15)); jBDeleteCurrentRecord.setForeground(Color.RED); jBDeleteAllRecords = new JButton("删除所有记录"); jBDeleteAllRecords.setBounds(358, 205, 155, 27); jPBottom.add(jBDeleteAllRecords); jBDeleteAllRecords.setFont(new Font("宋体", Font.ITALIC, 15)); jBDeleteAllRecords.setForeground(Color.RED); EXIT = new JButton("返回主页面"); EXIT.setBounds(527, 205, 155, 27); jPBottom.add(EXIT); EXIT.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { dispose(); Teacher ui=new Teacher(); } }); EXIT.setFont(new Font("宋体", Font.BOLD, 15)); EXIT.setForeground(Color.RED); EXIT.addActionListener(this); jBDeleteAllRecords.addActionListener(this); jBDeleteCurrentRecord.addActionListener(this); jBUpdate.addActionListener(this); jBInsert.addActionListener(this); getContentPane().setLayout(new GridLayout(2, 1)); this.setTitle("账号密码查改"); this.setSize(700, 568);// 改表的大小 this.setLocation(630, 180);// 改表的位置 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true);// 使页面显示 // this.setVisible(false);使页面消失 dbProcess = new DbProcess(); } // 监听器事件 public void actionPerformed(ActionEvent e) { // 事件判断 if (e.getActionCommand().equals("查询选择内容") && !jTFQueryField.getText().isEmpty()) { System.out.println("actionPerformed(). 查询选择内容"); String sQueryField = jTFQueryField.getText().trim(); int n=JOptionPane.showConfirmDialog(null,"确定查询该选项?", "账号密码记录",JOptionPane.YES_NO_OPTION); if(n==0) { queryProcess(sQueryField); jTFQueryField.setText(""); } } if (e.getActionCommand().equals("查询所有记录")) { System.out.println("actionPerformed(). 查询所有记录"); int n=JOptionPane.showConfirmDialog(null,"确定查询所有记录?", "账号密码记录",JOptionPane.YES_NO_OPTION); if(n==0) { queryAllProcess(); } } if (e.getActionCommand().equals("插入") && !jTFSTz.getText().isEmpty() && !jTFSTP.getText().isEmpty() && !jTFSSZ.getText().isEmpty() && !jTFSSP.getText().isEmpty() ) { System.out.println("actionPerformed(). 插入"); int n=JOptionPane.showConfirmDialog(null,"确定插入该条记录?", "账号密码记录",JOptionPane.YES_NO_OPTION); if(n==0) { insertProcess(); JOptionPane.showMessageDialog(null, " 插入成功", "插入成功", JOptionPane.PLAIN_MESSAGE); } } if (e.getActionCommand().equals("更新") && !jTFSTz.getText().isEmpty() && !jTFSTP.getText().isEmpty() && !jTFSSZ.getText().isEmpty() && !jTFSSP.getText().isEmpty() ) { System.out.println("actionPerformed(). 更新"); int n=JOptionPane.showConfirmDialog(null,"确定更新该条记录?", "账号密码记录",JOptionPane.YES_NO_OPTION); if(n==0) { JOptionPane.showMessageDialog(null, " 更新成功", "更新成功", JOptionPane.PLAIN_MESSAGE); updateProcess(); dispose(); Student_management_login_system sm=new Student_management_login_system(); } } if (e.getActionCommand().equals("删除当前记录")) { System.out.println("actionPerformed(). 删除当前记录"); int n=JOptionPane.showConfirmDialog(null,"注意:确定删除该条记录?", "账号密码记录",JOptionPane.YES_NO_OPTION); if(n==0) { JOptionPane.showMessageDialog(null, " 删除成功", "删除成功", JOptionPane.PLAIN_MESSAGE); deleteCurrentRecordProcess(); } } if (e.getActionCommand().equals("删除所有记录")) { System.out.println("actionPerformed(). 删除所有记录"); int n=JOptionPane.showConfirmDialog(null,"注意:确定删除所有记录?", "账号密码记录",JOptionPane.YES_NO_OPTION); if(n==0) { JOptionPane.showMessageDialog(null, " 全部删除成功", "全部删除成功", JOptionPane.PLAIN_MESSAGE); deleteAllRecordsProcess(); } } } // “查询”程序 public void queryProcess(String sQueryField) { try { // 建立查询条件 if(SelectQueryFieldStr=="老师账号"||SelectQueryFieldStr=="老师密码") { String sql = "SELECT `teacherdlb`.tuserNo,`teacherdlb`.tpswd FROM `teacherdlb` WHERE teacherdlb.tpswd IS NOT NULL AND "; String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr); System.out.println(queryFieldStr); sql = sql + queryFieldStr; sql = sql + " = "; sql = sql + "'" + sQueryField + "';"; String sql1 = "SELECT `studentdlb`.suserNo,`studentdlb`.spswd FROM `studentdlb` WHERE studentdlb.spswd IS NOT NULL ; "; System.out.println("queryProcess(). sql = " + sql); dbProcess.connect(); ResultSet rs = dbProcess.executeQuery(sql); ResultSet rs1 = dbProcess.executeQuery(sql1); // 将查询获得的记录数据,转换成适合生成JTable的数据形式 studentVector.clear(); while (rs.next()&&rs1.next()) { Vector v = new Vector(); v.add(rs.getString("tuserNo")); v.add(rs.getString("tpswd")); v.add(rs1.getString("suserNo")); v.add(rs1.getString("spswd")); studentVector.add(v);//显示表 } studentJTable.updateUI(); dbProcess.disconnect();} if(SelectQueryFieldStr=="学生账号"||SelectQueryFieldStr=="学生密码") { String sql = "SELECT `studentdlb`.suserNo,`studentdlb`.spswd FROM `studentdlb` WHERE studentdlb.spswd IS NOT NULL AND "; String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr); System.out.println(queryFieldStr); sql = sql + queryFieldStr; sql = sql + " = "; sql = sql + "'" + sQueryField + "';"; String sql1 = "SELECT `teacherdlb`.tuserNo,`teacherdlb`.tpswd FROM `teacherdlb` WHERE teacherdlb.tpswd IS NOT NULL ; "; System.out.println("queryProcess(). sql = " + sql); dbProcess.connect(); ResultSet rs = dbProcess.executeQuery(sql); ResultSet rs1 = dbProcess.executeQuery(sql1); // 将查询获得的记录数据,转换成适合生成JTable的数据形式 studentVector.clear(); while (rs.next()&&rs1.next()) { Vector v = new Vector(); v.add(rs1.getString("tuserNo")); v.add(rs1.getString("tpswd")); v.add(rs.getString("suserNo")); v.add(rs.getString("spswd")); studentVector.add(v);//显示表 } studentJTable.updateUI(); dbProcess.disconnect();} } catch (SQLException sqle) { System.out.println("sqle = " + sqle); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } } // “查询全部”程序 public void queryAllProcess() { try { // 建立查询条件 String sql = "SELECT `studentdlb`.suserNo,`studentdlb`.spswd FROM `studentdlb` WHERE studentdlb.spswd IS NOT NULL ;"; String sql1 = "SELECT `teacherdlb`.tuserNo,`teacherdlb`.tpswd FROM `teacherdlb` WHERE teacherdlb.tpswd IS NOT NULL ; "; System.out.println("queryProcess(). sql = " + sql); dbProcess.connect(); ResultSet rs = dbProcess.executeQuery(sql); ResultSet rs1 = dbProcess.executeQuery(sql1); // 将查询获得的记录数据,转换成适合生成JTable的数据形式 studentVector.clear(); while (rs.next()&&rs1.next()) { Vector v = new Vector(); v.add(rs1.getString("tuserNo")); v.add(rs1.getString("tpswd")); v.add(rs.getString("suserNo")); v.add(rs.getString("spswd")); studentVector.add(v);//显示表 } studentJTable.updateUI(); dbProcess.disconnect(); } catch (SQLException sqle) { System.out.println("sqle = " + sqle); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } } // “插入”程序 public void insertProcess() { String tuserNo = jTFSTz.getText().trim(); String tpswd = jTFSTP.getText().trim(); String suserNo = jTFSSZ.getText().trim(); String spswd = jTFSSP.getText().trim(); // 建立插入条件 String sql = "insert into `teacherdlb` values('"; sql = sql + tuserNo + "','"; sql = sql + tpswd + "');"; String sql1 = "insert into `studentdlb` values('"; sql1 = sql1 + suserNo + "','"; sql1 = sql1 + spswd + "');"; System.out.println("insertProcess(). sql = " + sql+"insertProcess(). sql1 = " + sql1); try { if (dbProcess.executeUpdate(sql) < 1||dbProcess.executeUpdate(sql1) < 1) { System.out.println("insertProcess(). insert database failed."); } } catch (Exception e) { System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } queryAllProcess(); } // “更新”程序 public void updateProcess() { String tuserNo = jTFSTz.getText().trim(); String tpswd = jTFSTP.getText().trim(); String suserNo = jTFSSZ.getText().trim(); String spswd = jTFSSP.getText().trim(); // 建立更新条件 String sql = "update teacherdlb set tpswd = '"; sql = sql + tpswd + "'"; sql = sql + " WHERE tuserNo = '" + tuserNo + "';"; String sql1 = "update studentdlb set spswd = '"; sql1 = sql1 + spswd + "'"; sql1 = sql1 + " WHERE suserNo = '" + suserNo + "';"; System.out.println("updateProcess(). sql = " + sql+"updateProcess(). sql1 = " + sql1); try { if (dbProcess.executeUpdate(sql) < 1||dbProcess.executeUpdate(sql1) < 1) { System.out.println("updateProcess(). update database failed."); } } catch (Exception e) { System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } queryAllProcess(); } // “删除”程序 public void deleteCurrentRecordProcess() { String tuserNo = jTFSTz.getText().trim(); String suserNo = jTFSSZ.getText().trim(); // 建立删除条件 String sql = "delete from teacherdlb where tuserNo = '" + tuserNo + "';"; String sql1 = "delete from studentdlb where suserNo = '" + suserNo + "';"; System.out.println("deleteCurrentRecordProcess(). sql = " + sql+"deleteCurrentRecordProcess(). sql1 = " + sql1); try { if (dbProcess.executeUpdate(sql) < 1||dbProcess.executeUpdate(sql1) < 1) { System.out.println("deleteCurrentRecordProcess(). delete database failed."); } } catch (Exception e) { System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } queryAllProcess(); } // “删除全部”程序 public void deleteAllRecordsProcess() { // 建立删除条件 String sql = "delete from teacherdlb;"; String sql1 = "delete from studentdlb;"; System.out.println("deleteAllRecordsProcess(). sql = " + sql+"deleteAllRecordsProcess(). sql1 = " + sql1); try { if (dbProcess.executeUpdate(sql) < 1||dbProcess.executeUpdate(sql1) < 1) { System.out.println("deleteAllRecordsProcess(). delete database failed."); } } catch (Exception e) { System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } queryAllProcess(); } public String jCBSelectQueryFieldTransfer(String InputStr) { String outputStr = ""; System.out.println("jCBSelectQueryFieldTransfer(). InputStr = " + InputStr); if (InputStr.equals("老师账号")) { outputStr = "tuserNo"; } else if (InputStr.equals("老师密码")) { outputStr = "tpswd"; } else if (InputStr.equals("学生账号")) { outputStr = "suserNo"; } else if (InputStr.equals("学生密码")) { outputStr = "spswd"; } System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr); return outputStr; } // 退出程序 public void close() { System.exit(0); } }
图3-3老师学生账号密码界面
3.4、新生信息输入界面
新生信息输入界面请见如图3-4新生信息输入界面。这个界面的设计同样是专门为教务办用户设计,首先这个界面是一个录入新生信息的界面,在每一个文本框都有相应输入的数据格式的提示比如生日的文本框所提示的内容是“2013-05-20”这种格式,因为在数据库中的学生信息表格中设计的时间的数据类型是date类型,所以必须用这种数据格式的填写才能成功插入到数据库相应的表格里面去。只有当所有的文本框中都输有正确数据,然后点击确认键,然后会弹出一个窗口让用户再确认一次是否允许该操作的执行,减少用户操作失误的几率。插入数据成功之后界面的所有文本框会清空,用户可以再继续将其他学生信息插入到学生信息表中;也可以点击返回,然后返回主界面。
实现新生信息输入界面的全部代码:
package xr06; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JOptionPane; import java.awt.Font; import java.awt.Color; import java.awt.SystemColor; import javax.swing.JTextField; import javax.swing.ButtonGroup; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JRadioButton; import javax.swing.ImageIcon; import java.awt.Toolkit; public class Newstudent extends JFrame { static String select="男"; ButtonGroup bg=null; private static DbProcess dbProcess; private JPanel contentPane; private JTextField textField; private JTextField textField_1; private JTextField textField_3; private JTextField textField_4; private JTextField textField_5; private JTextField textField_6; /** * Launch the application. */ public static void main(String[] args) { Newstudent f = new Newstudent(); } /** * Create the frame. */ public Newstudent() { setIconImage(Toolkit.getDefaultToolkit().getImage("G:\\timg-1.jpg")); this.setResizable(false); setFont(new Font("Dialog", Font.BOLD, 25)); setTitle("新生信息输入"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(700, 200, 570, 533); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JPanel panel = new JPanel(); panel.setBackground(new Color(255, 255, 153)); panel.setBounds(0, 0, 566, 498); contentPane.add(panel); panel.setLayout(null); JLabel lblNewLabel = new JLabel("新生信息输入"); lblNewLabel.setBounds(182, 13, 197, 36); lblNewLabel.setBackground(Color.LIGHT_GRAY); lblNewLabel.setFont(new Font("华文新魏", Font.BOLD, 30)); panel.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("学号:"); lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 20)); lblNewLabel_1.setBounds(92, 76, 71, 18); panel.add(lblNewLabel_1); JLabel label = new JLabel("姓名:"); label.setFont(new Font("宋体", Font.BOLD, 20)); label.setBounds(92, 126, 74, 18); panel.add(label); JLabel label_1 = new JLabel("性别:"); label_1.setFont(new Font("宋体", Font.BOLD, 20)); label_1.setBounds(92, 176, 70, 18); panel.add(label_1); JLabel label_2 = new JLabel("生日:"); label_2.setFont(new Font("宋体", Font.BOLD, 20)); label_2.setBounds(92, 226, 77, 18); panel.add(label_2); JLabel label_3 = new JLabel("地址:"); label_3.setFont(new Font("宋体", Font.BOLD, 20)); label_3.setBounds(92, 276, 66, 18); panel.add(label_3); textField = new JTextField(); textField.setBounds(162, 74, 255, 24); panel.add(textField); textField.setColumns(10); textField.addFocusListener(new JTextFieldHintListener("新生学号 如 1705", textField)); textField_1 = new JTextField(); textField_1.addFocusListener(new JTextFieldHintListener("新生姓名 如 XR", textField_1)); textField_1.setColumns(10); textField_1.setBounds(162, 124, 255, 24); panel.add(textField_1); textField_3 = new JTextField(); textField_3.addFocusListener(new JTextFieldHintListener("新生生日 如 2013-05-20", textField_3)); textField_3.setColumns(10); textField_3.setBounds(162, 224, 255, 24); panel.add(textField_3); textField_4 = new JTextField(); textField_4.addFocusListener(new JTextFieldHintListener("新生地址籍贯 如 湖南长沙", textField_4)); textField_4.setColumns(10); textField_4.setBounds(162, 274, 255, 24); panel.add(textField_4); JLabel label_4 = new JLabel("院系:"); label_4.setFont(new Font("宋体", Font.BOLD, 20)); label_4.setBounds(92, 326, 66, 18); panel.add(label_4); textField_5 = new JTextField(); textField_5.addFocusListener(new JTextFieldHintListener("新生院系 如 0101", textField_5)); textField_5.setColumns(10); textField_5.setBounds(162, 324, 255, 24); panel.add(textField_5); JLabel label_5 = new JLabel("班名:"); label_5.setFont(new Font("宋体", Font.BOLD, 20)); label_5.setBounds(92, 376, 66, 18); panel.add(label_5); textField_6 = new JTextField(); textField_6.addFocusListener(new JTextFieldHintListener("新生班名 如 01", textField_6)); textField_6.setColumns(10); textField_6.setBounds(162, 374, 255, 24); panel.add(textField_6); JButton btnNewButton = new JButton("确认"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if ( !textField.getText().isEmpty() && !textField_1.getText().isEmpty() && !textField_3.getText().isEmpty() && !textField_4.getText().isEmpty() && !textField_5.getText().isEmpty() && !textField_6.getText().isEmpty()) { System.out.println("mouseClicked(). 确认"); int n=JOptionPane.showConfirmDialog(null,"确定录入该生信息?", "新生信息录入",JOptionPane.YES_NO_OPTION); if(n==0) { insertProcess(); JOptionPane.showMessageDialog(null, " 录入信息成功", "输入信息成功", JOptionPane.PLAIN_MESSAGE); textField.setText(""); textField_1.setText(""); textField_3.setText(""); textField_4.setText(""); textField_5.setText(""); textField_6.setText(""); } } else {JOptionPane.showMessageDialog(null, " 请输入完整数据,谢谢", "请输入完整数据", JOptionPane.PLAIN_MESSAGE); } } }); btnNewButton.setForeground(Color.BLACK); btnNewButton.setBackground(Color.ORANGE); btnNewButton.setFont(new Font("宋体", Font.BOLD, 20)); btnNewButton.setBounds(322, 433, 95, 35); panel.add(btnNewButton); JButton button = new JButton("返回"); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { dispose(); Teacher t = new Teacher(); } }); button.setForeground(Color.RED); button.setFont(new Font("宋体", Font.BOLD, 20)); button.setBackground(Color.ORANGE); button.setBounds(438, 433, 95, 35); panel.add(button); JRadioButton rdbtnNewRadioButton = new JRadioButton("男"); rdbtnNewRadioButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { System.out.println("选择“男”"); select="男"; } }); rdbtnNewRadioButton.setFont(new Font("宋体", Font.BOLD, 17)); rdbtnNewRadioButton.setBackground(new Color(255, 255, 153)); rdbtnNewRadioButton.setBounds(162, 174, 77, 27); panel.add(rdbtnNewRadioButton); JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("女"); rdbtnNewRadioButton_1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { System.out.println("选择“女”"); select="女"; } }); rdbtnNewRadioButton_1.setFont(new Font("宋体", Font.BOLD, 17)); rdbtnNewRadioButton_1.setBackground(new Color(255, 255, 153)); rdbtnNewRadioButton_1.setBounds(238, 174, 157, 27); panel.add(rdbtnNewRadioButton_1); this.setVisible(true); bg=new ButtonGroup(); bg.add(rdbtnNewRadioButton); bg.add(rdbtnNewRadioButton_1); rdbtnNewRadioButton.setSelected(true); dbProcess = new DbProcess(); } public void insertProcess() { String Sno = textField.getText().trim(); String Sname = textField_1.getText().trim(); String Ssex = select; String Sbirth = textField_3.getText().trim(); String Sadd = textField_4.getText().trim(); String Sacademy = textField_5.getText().trim(); String Scla = textField_6.getText().trim(); // 建立插入条件 String sql = "insert into student values('"; sql = sql + Sno + "','"; sql = sql + Sname + "','"; sql = sql + Ssex + "','"; sql = sql + Sbirth + "','"; sql = sql + Sadd + "','"; sql = sql + Sacademy + "','"; sql = sql + Scla + "');"; System.out.println("insertProcess(). sql = " + sql); try { if (dbProcess.executeUpdate(sql) < 1) { System.out.println("insertProcess(). insert database failed."); } } catch (Exception e) { System.out.println("e = " + e); JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE); } } }
图3-4新生信息输入界面
以上只是数据库课设之学生信息管理系统部分设计内容和源代码资源,如果想要学生信息管理系统全部资源请点击下面资源链接进行下载,希望能帮助到你!
独家资源1:点击资源下载链接
独家资源2:点击打开资源链接