本系统主要的功能是收集学生的个人信息,以便向教师提供每个学生在校的情况。系统的主要功能有:
① 学生个人信息输入,包括:姓名、性别、院系、生日、籍贯、生源所在地等。
② 学生流动情况的输入,包括:转系、休学、复学、退学、毕业。
③ 奖惩情况的输入。
④ 学生个人情况查询和修改,包括流动情况和奖罚情况。
① 学生:学号、姓名、性别、生日、籍贯、所在院系、所在班级。
② 处罚记录:记录号、级别、处罚对象、记录时间、详细描述、是否生效。
③ 奖励记录:记录号、级别、奖励对象、记录时间、详细描述。
④ 学籍变更记录:记录号、变更情况、记录对象、记录时间、详细描述。
⑤ 班级:班级编号、班级名称、所属院系。
⑥ 院系:代码、名称
代码 | 说明 |
---|---|
0 | 转系 |
1 | 休学 |
2 | 复学 |
3 | 退学 |
4 | 毕业 |
代码 | 说明 |
---|---|
0 | 校特等奖学金 |
1 | 校一等奖学金 |
2 | 校二等奖学金 |
3 | 校三等奖学金 |
4 | 系一等奖学金 |
5 | 系二等奖学金 |
6 | 系三等奖学金 |
代码 | 说明 |
---|---|
0 | 警告 |
1 | 严重警告 |
2 | 记过 |
3 | 记大过 |
4 | 开除 |
链接: 关于eclipse连接数据库的简单操作.
/*用户注册页面的全部代码*/
package kcsj_mysqlOrjava; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import java.awt.Font; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.plaf.basic.BasicInternalFrameTitlePane.IconifyAction; import org.apache.commons.dbutils.QueryRunner; import org.eclipse.jface.text.templates.GlobalTemplateVariables.User; import javax.swing.JComboBox; import javax.swing.JButton; import javax.swing.DefaultComboBoxModel; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.sql.Connection; import java.sql.Statement; import java.awt.event.ActionEvent; import javax.swing.SwingConstants; import javax.swing.JCheckBox; public class register_frame { private JFrame register; private JTextField textField_username; private JTextField textField_password; private JTextField textField_rightKey; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { register_frame window = new register_frame(); window.register.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public register_frame() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { register = new JFrame(); register.getContentPane().setBackground(Color.PINK); register.getContentPane().setForeground(Color.LIGHT_GRAY); register.setBounds(100, 100, 450, 300); register.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); register.setLocationRelativeTo(null);//将登录界面置于屏幕中间 JLabel label_register = new JLabel("\u7528\u6237\u6CE8\u518C"); label_register.setFont(new Font("方正粗黑宋简体", Font.PLAIN, 25)); JLabel label_user = new JLabel("\u7528\u6237\u540D\uFF1A"); label_user.setFont(new Font("楷体", Font.PLAIN, 19)); JLabel label_password = new JLabel("\u5BC6\u7801\uFF1A"); label_password.setFont(new Font("楷体", Font.PLAIN, 19)); textField_username = new JTextField(); textField_username.setColumns(10); textField_password = new JPasswordField(); ((JPasswordField) textField_password).setEchoChar('*'); textField_password.setColumns(10); JComboBox comboBox_user = new JComboBox(); comboBox_user.setModel(new DefaultComboBoxModel(new String[] {"\u5B66\u751F", "\u8001\u5E08"})); JLabel label_select = new JLabel("\u7528\u6237\u7C7B\u578B\uFF1A"); label_select.setFont(new Font("楷体", Font.PLAIN, 17)); //注册确认按钮板块 JButton button_right = new JButton("\u786E\u5B9A"); button_right.addActionListener(new ActionListener() { /*注册确认按钮实现的代码*/ public void actionPerformed(ActionEvent e) { if (e.getSource()==button_right) {//用户点击了确认按钮 /*判断用户行为,显示相应窗口*/ if (textField_username.getText().toString().equals("")) { JOptionPane.showMessageDialog(null, "请输入用户名和密码","友情提示",2);//用户用户名和密码均未输入 }else if (textField_password.getText().toString().equals("")) { JOptionPane.showMessageDialog(null, "请输入密码","友情提示",2);//用户未输入密码 }else if (textField_username.getText().toString().equals("")) { JOptionPane.showMessageDialog(null, "请输入用户名","友情提示",2);//用户未输入用户名 }else if (textField_rightKey.getText().toString().equals("")) { JOptionPane.showMessageDialog(null, "请确认密码,保证两次输入密码相同","友情提示",2);//用户未确认密码 }else {//用户所有信息均已输入且满足确认的要求 if (textField_rightKey.getText().toString().equals(textField_password.getText().toString())) {//两次输入密码相同 if (comboBox_user.getSelectedItem().toString().equals("老师")) {//判断出用户类型为老师 String sql="Insert Into register_teacher(username,password) values(?,?)";//编写sql语句 sqlUpdate.update(sql, textField_username.getText().toString(),textField_password.getText().toString());//调用自定义函数将老师的账号和密码插入到数据库中 JOptionPane.showMessageDialog(null, "注册成功"); }else {//判断出用户类型为学生 String sql="Insert Into register_student(username,password) values(?,?)";//编写sql语句 sqlUpdate.update(sql, textField_username.getText().toString(),textField_password.getText().toString());//调用自定义函数将学生的账号和密码插入到数据库中 JOptionPane.showMessageDialog(null, "注册成功"); } new xt_application().main(null);//打开登录窗口 register.dispose();//关闭注册窗口 }else {//两次输入密码不同 JOptionPane.showMessageDialog(null, "两次输入的密码不一致","友情提示",2); } } } }}); button_right.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); //注册返回按钮板块 /*返回按钮代码实现*/ JButton button_back = new JButton("\u8FD4\u56DE"); button_back.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource()==button_back) { new xt_application().main(null);//打开登录窗口 register.dispose();//关闭注册窗口 } } }); button_back.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); JButton button_exit = new JButton("\u9000\u51FA"); button_exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource()==button_exit) { int isExit=JOptionPane.showConfirmDialog(null, "您确定要退出系统吗?","友情提示",JOptionPane.YES_NO_OPTION);//提示用户是否要退出系统 if (isExit==0) { register.dispose(); } } } }); button_exit.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); JLabel label_rightKey = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A"); label_rightKey.setFont(new Font("楷体", Font.PLAIN, 19)); textField_rightKey = new JPasswordField(); ((JPasswordField) textField_rightKey).setEchoChar('*'); textField_rightKey.setColumns(10); //显示密码选项框板块 /*显示密码选项框代码实现*/ JCheckBox JcheckBox_pwd = new JCheckBox("\u663E\u793A\u5BC6\u7801"); JcheckBox_pwd.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // TODO 自动生成的方法存根 if (e.getStateChange()==ItemEvent.SELECTED) { ((JPasswordField) textField_password).setEchoChar((char)0); }else { ((JPasswordField) textField_password).setEchoChar('*'); } } }); JcheckBox_pwd.setFont(new Font("楷体", Font.PLAIN, 17)); JcheckBox_pwd.setBackground(Color.PINK); JcheckBox_pwd.setForeground(Color.WHITE); //显示密码选项框板块 /*显示密码选项框代码实现*/ JCheckBox JchectBox_rightKey = new JCheckBox("\u663E\u793A\u5BC6\u7801"); JchectBox_rightKey.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // TODO 自动生成的方法存根 if (e.getStateChange()==ItemEvent.SELECTED) { ((JPasswordField) textField_rightKey).setEchoChar((char)0); }else { ((JPasswordField) textField_rightKey).setEchoChar('*'); } } }); JchectBox_rightKey.setBackground(Color.PINK); JchectBox_rightKey.setForeground(Color.WHITE); JchectBox_rightKey.setFont(new Font("楷体", Font.PLAIN, 17)); GroupLayout groupLayout = new GroupLayout(register.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(165) .addComponent(label_register)) .addGroup(groupLayout.createSequentialGroup() .addGap(48) .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addComponent(label_user) .addComponent(label_select) .addComponent(label_rightKey) .addComponent(label_password)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(comboBox_user, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE) .addGroup(groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false) .addComponent(textField_rightKey, Alignment.LEADING) .addComponent(textField_password, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) .addComponent(JchectBox_rightKey, 0, 0, Short.MAX_VALUE) .addComponent(JcheckBox_pwd, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addComponent(textField_username, GroupLayout.PREFERRED_SIZE, 231, GroupLayout.PREFERRED_SIZE)) .addGap(36)) .addGroup(groupLayout.createSequentialGroup() .addGap(72) .addComponent(button_right, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(button_back, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE) .addGap(18) .addComponent(button_exit, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap() .addComponent(label_register) .addGap(18) .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addComponent(label_user) .addComponent(textField_username, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(8) .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addComponent(label_password) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(textField_password, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(JcheckBox_pwd))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(label_rightKey) .addComponent(textField_rightKey, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(JchectBox_rightKey)) .addGap(10) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(comboBox_user, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label_select)) .addGap(18) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(button_right) .addComponent(button_back) .addComponent(button_exit)) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); register.getContentPane().setLayout(groupLayout); } }
/*用户登录界面的全部代码*/
package kcsj_mysqlOrjava; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JPasswordField; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.sql.ResultSet; import java.awt.event.ActionEvent; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import java.awt.Font; import java.awt.HeadlessException; import javax.swing.SwingConstants; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.internal.win32.TCHITTESTINFO; import java.awt.Window; import com.mysql.cj.util.StringUtils; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.JComboBox; import javax.security.auth.login.LoginContext; import javax.swing.DefaultComboBoxModel; import javax.swing.JCheckBox; import javax.swing.ImageIcon; public class xt_application { private JFrame login; private JTextField user_text; private JTextField key_text; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { xt_application window = new xt_application(); window.login.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public xt_application() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { login = new JFrame(); login.getContentPane().setForeground(Color.LIGHT_GRAY); login.getContentPane().setBackground(Color.LIGHT_GRAY); login.setBackground(Color.LIGHT_GRAY); login.setBounds(100, 100, 849, 598); login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); login.setLocationRelativeTo(null);//将登录界面置于屏幕中间 JLabel title = new JLabel("\u5B66\u751F\u7BA1\u7406\u7CFB\u7EDF"); title.setBounds(532, 304, 164, 46); title.setHorizontalAlignment(SwingConstants.CENTER); title.setForeground(Color.GRAY); title.setFont(new Font("方正粗黑宋简体", Font.PLAIN, 25)); title.setBackground(Color.BLACK); JLabel user = new JLabel("\u7528\u6237\u540D\uFF1A"); user.setBounds(448, 363, 76, 22); user.setFont(new Font("楷体", Font.PLAIN, 19)); JLabel key = new JLabel("\u5BC6\u7801\uFF1A"); key.setBounds(467, 408, 57, 22); key.setFont(new Font("楷体", Font.PLAIN, 19)); user_text = new JTextField(); user_text.setBounds(532, 364, 243, 24); user_text.setColumns(10); key_text = new JPasswordField(); key_text.setBounds(532, 409, 135, 24); key_text.setColumns(10); ((JPasswordField) key_text).setEchoChar('*'); JLabel user_type = new JLabel("\u7528\u6237\u7C7B\u578B\uFF1A"); user_type.setBounds(439, 462, 85, 20); user_type.setFont(new Font("楷体", Font.PLAIN, 17)); JComboBox user_type_comboBox = new JComboBox(); user_type_comboBox.setBounds(532, 461, 128, 24); user_type_comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u5B66\u751F", "\u8001\u5E08"})); user_type_comboBox.setToolTipText(""); //登录按钮板块 JButton button_login = new JButton("\u767B\u5F55"); button_login.setBounds(430, 506, 94, 33); button_login.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); /*登录按钮的代码实现*/ button_login.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根 String name=user_text.getText().toString();//用户名 String key=key_text.getText().toString();//密码 String idtf=user_type_comboBox.getSelectedItem().toString(); if (e.getActionCommand().equals("登录")) { if (name.isEmpty()&&!key.isEmpty()) {//用户未输入用户名,只输入了密码 JOptionPane.showMessageDialog(null,"用户名不能为空","友情提示",2);//弹出用户名为空的提示性对话框 }else if (key.isEmpty()&&!name.isEmpty()) {//用户只输入了用户名而未输入密码 JOptionPane.showMessageDialog(null, "密码不能为空","友情提示",2);//弹出密码为空的提示性对话框 }else if (key.isEmpty()&&name.isEmpty()) {//用户均未输入用户名和密码 JOptionPane.showMessageDialog(null, "用户名和密码不能为空","友情提示",2);//弹出用户名和密码均为空的提示性对话框 }else { if (idtf.equals("学生")) {//当用户类型为学生时 try { if (name.equals(sqlUpdate.user_Query("select username from register_student where username=?", name))) {//在数据库中查询到指定用户名 if (key.equals(sqlUpdate.pwd_Query("select password from register_student where password=?", key))) {//在数据库中查询到用户名所对应的密码 stu_menu_frame f=new stu_menu_frame();//由于getId()未设置为静态方法,故必须新设对象一调用getId()方法 f.getId(sqlUpdate.id_Query("select id from register_student where username=?", name));//调用stu_menu_frame中的getId()方法,达到传参的目的 new stu_menu_frame().main(null);//验证身份成功,登录成功 login.dispose();//关闭登录页面 }else { JOptionPane.showMessageDialog(null, "密码错误,请重新输入","友情提示",2);//密码错误,验证身份失败,登录失败 } }else { JOptionPane.showMessageDialog(null, "用户名不存在","友情提示",2);//用户名不存在或者用户类型不符合 } } catch (HeadlessException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } catch (Exception e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } }else {//当用户类型为老师时 try { if (name.equals(sqlUpdate.user_Query("select username from register_teacher where username=?", name))) {//在数据库中查询到指定用户名 if (key.equals(sqlUpdate.pwd_Query("select password from register_teacher where password=?", key))) {//在数据库中查询到用户名所对应的密码 tea_menu_frame tea=new tea_menu_frame();//由于getId()未设置为静态方法,故必须新设对象——调用getId()方法 tea.getId(sqlUpdate.id_Query("select id from register_teacher where username=?", name));//调用tea_menu_frame中的getId()方法,达到传参的目的 new tea_menu_frame().main(null);//验证身份成功,登录成功 login.dispose();//关闭登录页面 }else { JOptionPane.showMessageDialog(null, "密码错误,请重新输入","友情提示",2);//密码错误,验证身份失败,登录失败 } }else { JOptionPane.showMessageDialog(null, "用户名不存在","友情提示",2);//用户名不存在或者用户类型不符合 } } catch (HeadlessException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } catch (Exception e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } } } } } }); //重置按钮板块 JButton button_resetting = new JButton("\u91CD\u7F6E"); button_resetting.setBounds(557, 506, 91, 33); button_resetting.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); /*重置按钮的代码实现*/ button_resetting.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根 user_text.setText("");/*将输入框置空*/ key_text.setText(""); user_type_comboBox.setSelectedIndex(0); } }); //退出按钮板块 JButton button_exit = new JButton("\u9000\u51FA"); button_exit.setBounds(687, 506, 88, 33); button_exit.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); /*退出按钮的代码实现*/ button_exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根 if (e.getActionCommand().toString().equals("退出")) {//捕获到用户行为 int isExit = JOptionPane.showConfirmDialog(null, "您确定要退出系统吗?","友情提示",JOptionPane.YES_NO_OPTION);//提示用户是否要退出系统 if(isExit==0) login.dispose();//退出系统 } } }); //用户注册按钮板块 JButton button_register = new JButton("\u6CE8\u518C"); button_register.setBounds(687, 455, 88, 33); /*注册按钮的代码实现(直接退出登录窗口,打开注册窗口)*/ button_register.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new register_frame().main(null);//打开注册 login.dispose();//关闭登录窗口 } }); button_register.setFont(new Font("微软雅黑 Light", Font.BOLD, 17)); //显示密码的选择框 JCheckBox checkBox_toSeeKey = new JCheckBox("\u663E\u793A\u5BC6\u7801"); checkBox_toSeeKey.setBounds(671, 406, 93, 29); checkBox_toSeeKey.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // TODO 自动生成的方法存根 if (e.getStateChange()==ItemEvent.SELECTED) {//选择框被选中 ((JPasswordField) key_text).setEchoChar((char)0); }else { ((JPasswordField) key_text).setEchoChar('*');//将密码显示为*加密后的密文 } } }); checkBox_toSeeKey.setForeground(Color.WHITE); checkBox_toSeeKey.setFont(new Font("楷体", Font.PLAIN, 17)); checkBox_toSeeKey.setBackground(Color.LIGHT_GRAY); login.getContentPane().setLayout(null); login.getContentPane().add(user); login.getContentPane().add(key); login.getContentPane().add(button_login); login.getContentPane().add(user_type); login.getContentPane().add(title); login.getContentPane().add(button_resetting); login.getContentPane().add(user_type_comboBox); login.getContentPane().add(button_register); login.getContentPane().add(button_exit); login.getContentPane().add(key_text); login.getContentPane().add(checkBox_toSeeKey); login.getContentPane().add(user_text); JPanel panel = new JPanel(); panel.setBounds(0, 0, 363, 557); login.getContentPane().add(panel); panel.setLayout(null); JLabel lblNewLabel = new JLabel("New label"); lblNewLabel.setIcon(new ImageIcon(xt_application.class.getResource("/images/\u594B\u6597.png"))); lblNewLabel.setBounds(0, -19, 363, 600); panel.add(lblNewLabel); JPanel panel_1 = new JPanel(); panel_1.setBounds(362, 0, 469, 302); login.getContentPane().add(panel_1); panel_1.setLayout(null); JLabel lblNewLabel_1 = new JLabel(""); lblNewLabel_1.setIcon(new ImageIcon(xt_application.class.getResource("/images/\u9633\u5149\u4E0B.jpeg"))); lblNewLabel_1.setBounds(0, -29, 469, 341); panel_1.add(lblNewLabel_1); } }
/*学生主页面的全部代码*/
package kcsj_mysqlOrjava; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JMenuBar; import javax.security.auth.login.LoginContext; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.event.MenuDragMouseEvent; import javax.swing.event.MenuDragMouseListener; import org.eclipse.swt.internal.mozilla.nsIWebBrowser; import org.eclipse.swt.internal.win32.TCHITTESTINFO; import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JDesktopPane; import java.awt.Color; import javax.swing.SwingConstants; import javax.swing.JLabel; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JButton; import javax.swing.LayoutStyle.ComponentPlacement; public class stu_menu_frame { private JFrame menu_frame; private static int s_id;//设置student表中的id号 public void getId(int id) { s_id=id;//接收来自register_student表中的id号,在后续操作中将该id号值赋予student表id栏目值 } /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { stu_menu_frame window = new stu_menu_frame(); window.menu_frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public stu_menu_frame() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { menu_frame = new JFrame(); menu_frame.getContentPane().setBackground(Color.PINK); menu_frame.setBounds(100, 100, 450, 300); menu_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menu_frame.setLocationRelativeTo(null); JMenuBar menuBar = new JMenuBar(); menu_frame.setJMenuBar(menuBar); JMenu menu_xtsz = new JMenu("\u83DC\u5355"); menuBar.add(menu_xtsz); /*菜单中菜单项修改密码的按钮板块*/ JMenuItem menuItem_change_key = new JMenuItem("\u4FEE\u6539\u5BC6\u7801"); menu_xtsz.add(menuItem_change_key); menuItem_change_key.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 if (e.getSource()==menuItem_change_key) {//捕获到用户点击了菜单项修改密码的按钮 stu_change_key_frame change_key=new stu_change_key_frame();//由于change_key_frame类中的getId()方法不是静态方法,所以必须先创建对象 change_key.getId(s_id);//调用getId()传参 new stu_change_key_frame().main(null);//打开修改密码的窗口 menu_frame.dispose();//关闭菜单窗口 } } @Override public void mouseExited(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseEntered(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseClicked(MouseEvent e) {}// TODO 自动生成的方法存根 }); /*菜单中菜单项返回登录页面的按钮板块*/ JMenuItem menuItem_back_xt = new JMenuItem("\u8FD4\u56DE\u767B\u5F55\u754C\u9762"); menu_xtsz.add(menuItem_back_xt); menuItem_back_xt.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 if (e.getSource()==menuItem_back_xt) {//捕获到用户点击了返回登录界面的菜单选项 new xt_application().main(null);//打开登录窗口 menu_frame.dispose();//关闭菜单窗口 } } @Override public void mouseExited(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseEntered(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseClicked(MouseEvent e) {}// TODO 自动生成的方法存根 }); /*菜单中菜单项退出系统的按钮板块*/ JMenuItem menuItem_exit = new JMenuItem("\u9000\u51FA\u7CFB\u7EDF"); menu_xtsz.add(menuItem_exit); menuItem_exit.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 if (e.getSource()==menuItem_exit) { int isExit = JOptionPane.showConfirmDialog(null, "您确定要退出系统吗?","友情提示",JOptionPane.YES_NO_OPTION); if (isExit==0) { menu_frame.dispose(); } } } @Override public void mouseExited(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseEntered(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseClicked(MouseEvent e) {}// TODO 自动生成的方法存根 }); JMenu menu_finInfomation = new JMenu("\u5B8C\u5584\u4FE1\u606F"); menuBar.add(menu_finInfomation); JMenuItem menuItem_confirm = new JMenuItem("\u5B9E\u540D\u8BA4\u8BC1"); menu_finInfomation.add(menuItem_confirm); menuItem_confirm.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 if (e.getSource()==menuItem_confirm) { try { confrim_frame confrim=new confrim_frame();//由于getId()并没有设置为confrim_frame类中的静态方法,所以必须新建立对象才能调用方法 confrim.getId(s_id);//想confrim_frame类中传参 /*isId是id_Query()方法的返回值,若数据库中已存在该s_id号,方法返回值为id值,说明在此之前用户已经完善过信息,无需完善,若方法返回0值,说明此前用户未完善信息*/ int isId = sqlUpdate.id_Query("select id from student where id=?", s_id);//查找数据库中是否存在登录界面传来的id号 if (isId!=0) {//若id号存在说明该用户无需完善信息 JOptionPane.showMessageDialog(null, "信息已足够完善","友情提示",2); }else {//若id号不存在说明该用户是新用户,需要完善信息 new confrim_frame().main(null);//打开完善信息页面 } } catch (Exception e2) { // TODO: handle exception e2.printStackTrace(); } } } @Override public void mouseExited(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseEntered(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseClicked(MouseEvent e) {}// TODO 自动生成的方法存根 }); JMenu menu_query = new JMenu("\u67E5\u8BE2\u4FE1\u606F"); menuBar.add(menu_query); /*查询信息中的基本信息板块*/ JMenuItem menuItem_queryInformation = new JMenuItem("\u57FA\u672C\u4FE1\u606F"); menu_query.add(menuItem_queryInformation); menuItem_queryInformation.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 if (e.getSource()==menuItem_queryInformation) { stu_queryInformation queryInformation=new stu_queryInformation();//由于stu_queryInformation是非静态方法,所以必须先创建对象 queryInformation.getId(s_id);//调用方法传参 new stu_queryInformation().main(null); menu_frame.dispose(); } } @Override public void mouseExited(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseEntered(MouseEvent e) {}// TODO 自动生成的方法存根 @Override public void mouseClicked(MouseEvent e) {}// TODO 自动生成的方法存根 }); JMenuItem menuItem_change = new JMenuItem("\u5B66\u7C4D\u53D8\u66F4"); menu_query.add(menuItem_change); menuItem_change.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {} @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 stu_query_xj s=new stu_query_xj();//由于getId()未被定义为静态方法,所以必须创建对象 s.getId(s_id); menu_frame.dispose();//关闭当前窗口 new stu_query_xj().main(null);//打开新窗口 } @Override public void mouseExited(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseClicked(MouseEvent e) {} }); JMenuItem menuItem_great = new JMenuItem("\u5956\u52B1\u8BB0\u5F55"); menu_query.add(menuItem_great); menuItem_great.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {} @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 stu_query_reward s=new stu_query_reward();//由于getId()未被定义为静态方法,所以必须创建对象 s.getId(s_id); menu_frame.dispose();//关闭当前窗口 new stu_query_reward().main(null);//打开新窗口 } @Override public void mouseExited(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseClicked(MouseEvent e) {} }); JMenuItem menuItem_bad = new JMenuItem("\u5904\u5206\u8BB0\u5F55"); menu_query.add(menuItem_bad); menuItem_bad.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) {} @Override public void mousePressed(MouseEvent e) { // TODO 自动生成的方法存根 stu_query_punish s=new stu_query_punish();//由于getId()未被定义为静态方法,所以必须创建对象 s.getId(s_id); menu_frame.dispose();//关闭当前窗口 new stu_query_punish().main(null);//打开新窗口 } @Override public void mouseExited(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseClicked(MouseEvent e) {} }); JLabel label_welcome = new JLabel("\u6B22\u8FCE\u6765\u5230\u5B66\u751F\u7BA1\u7406\u7CFB\u7EDF"); label_welcome.setForeground(Color.WHITE); label_welcome.setFont(new Font("华文行楷", Font.BOLD, 31)); label_welcome.setHorizontalAlignment(SwingConstants.TRAILING); JButton button_stuToDo = new JButton("\u5B66\u751F\u624B\u518C"); JLabel label_prompt = new JLabel("\u6E29\u99A8\u63D0\u793A\uFF1A\u65B0\u624B\u5165\u5B66\u8BF7\u5148\u9605\u8BFB\u5B66\u751F\u624B\u518C\uFF0C\u5E76\u5B8C\u5584\u4E2A\u4EBA\u4FE1\u606F"); label_prompt.setForeground(Color.RED); label_prompt.setFont(new Font("华文楷体", Font.PLAIN, 15)); label_prompt.setHorizontalAlignment(SwingConstants.TRAILING); GroupLayout groupLayout = new GroupLayout(menu_frame.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap(53, Short.MAX_VALUE) .addComponent(label_welcome) .addGap(49)) .addGroup(groupLayout.createSequentialGroup() .addContainerGap(33, Short.MAX_VALUE) .addComponent(label_prompt) .addGap(24)) .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup() .addGap(167) .addComponent(button_stuToDo) .addContainerGap(172, Short.MAX_VALUE)) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(45) .addComponent(label_welcome) .addGap(23) .addComponent(button_stuToDo) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(label_prompt) .addContainerGap(66, Short.MAX_VALUE)) ); menu_frame.getContentPane().setLayout(groupLayout); } }
/*学生类的全部代码*/
package kcsj_mysqlOrjava; public class Student { private int studentId; public Student(int studentId2, String name2, String sex2, int classid2, String collage2, String born2, String resident2) { // TODO 自动生成的构造函数存根 this.studentId=studentId2; this.name=name2; this.sex=sex2; this.classid=classid2; this.collage=collage2; this.born=born2; this.resident=resident2; } public int getStudentId() { return studentId; } public void setStudentId(int studentId) { this.studentId = studentId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public int getClassid() { return classid; } public void setClassid(int classid) { this.classid = classid; } public String getCollage() { return collage; } public void setCollage(String collage) { this.collage = collage; } public String getBorn() { return born; } public void setBorn(String born) { this.born = born; } public String getResident() { return resident; } public void setResident(String resident) { this.resident = resident; } public String getXj_information() { return xj_information; } public void setXj_information(String xj_information) { this.xj_information = xj_information; } public String getReward_information() { return reward_information; } public void setReward_information(String reward_information) { this.reward_information = reward_information; } public String getPunish_information() { return punish_information; } public void setPunish_information(String punish_information) { this.punish_information = punish_information; } public String getIsRight() { return isRight; } public void setIsRight(String isRight) { this.isRight = isRight; } private String name; private String sex; private int classid; private String collage; private String born; private String resident; private String xj_information; private String reward_information; private String punish_information; private String isRight; }
/*封装类的全部代码*/
package kcsj_mysqlOrjava; import java.awt.List; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import javax.management.RuntimeErrorException; import com.mysql.cj.PerConnectionLRUFactory; public class sqlUpdate { /*执行增删改查*/ public static int update(String sql,Object...params) {//执行增删改查 try { //1、获取连接 Connection con = connection.getConnection(); //2、执行sql语句 PreparedStatement statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } int update=statement.executeUpdate(); return update; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); } } /*查询学生的姓名*/ public static String name_query(String sql,Object...params) throws Exception{ Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { con=connection.getConnection(); statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getString("s_name"); } return null; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询学生的学籍和奖励和处分信息*/ public static String xj_rReward_Punish_query(String sql,Object...params) throws Exception{ Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { con=connection.getConnection(); statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getString("DESCRIPTION"); } return null; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询学生的处分是否生效*/ public static String IsPunish_query(String sql,Object...params) throws Exception{ Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { con=connection.getConnection(); statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getString("ENABLE"); } return null; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询学生的相关信息并返回该学生*/ public static java.util.List<Student> Student_Query(String sql,Object...params) throws Exception { Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { //1、获取连接 con=connection.getConnection(); //2、执行查询 statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); java.util.List<Student> list=new ArrayList<>(); while (set.next()) { int studentId=set.getInt("s_studentid"); String name=set.getString("s_name"); String sex=set.getString("s_sex"); int classid=set.getInt("s_classid"); String collage=set.getString("s_collage"); String born=set.getString("s_born"); String resident=set.getString("s_resident"); Student stu=new Student(studentId, name, sex, classid, collage, born, resident); list.add(stu); } return list; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询用户名*/ public static String user_Query(String sql,Object...params) throws Exception { Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { //1、获取连接 con=connection.getConnection(); //2、执行查询 statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getString("username"); } return null; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询学籍代码的描述*/ public static String description_Query(String sql,Object...params) throws Exception { Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { con=connection.getConnection(); statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getString("DESCRIPTION"); } return null; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询密码*/ public static String pwd_Query(String sql,Object...params) throws Exception { Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { //1、获取连接 con=connection.getConnection(); //2、执行查询 statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getString("password"); } return null; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } /*查询id号*/ public static int id_Query(String sql,Object...params) throws Exception { Connection con=null; PreparedStatement statement=null; ResultSet set=null; try { //1、获取连接 con=connection.getConnection(); //2、执行查询 statement=con.prepareStatement(sql); for (int i = 0; i < params.length; i++) { statement.setObject(i+1, params[i]); } set=statement.executeQuery(); if (set.next()) { return set.getInt("id"); } else return 0; } catch (Exception e) { // TODO: handle exception throw new RuntimeException(e); }finally { connection.close(set, con); } } }
以上展示了此项目的部分代码,页面算不上美观,有不足的地方还请各位大佬指正。