学生管理系统(图形界面)——Java

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

学生管理系统(图形界面)——Java源代码:packageexp10;importjavax.swing.JFrame;publicclassMainClass{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubJFramemyFrame=newJFrame(学生成绩管理系统);myFrame.setLocation(300,100);//myFrame.setContentPane(newLoginPane(myFrame));myFrame.pack();myFrame.setVisible(true);}}packageexp10;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassDataBase{Connectionconn=null;publicConnectiongetConn(){returnthis.conn;}publicvoidsetConn(Connectionconn){this.conn=conn;}publicbooleangetConnection(){Stringurl=jdbc:mysql://localhost:3306/ScoreManagement?user=root&password=123;try{Class.forName(org.gjt.mm.mysql.Driver);conn=DriverManager.getConnection(url);returntrue;}catch(SQLExceptione){System.out.println(e.getMessage());returnfalse;}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();returnfalse;}}publicResultSetexecuteQuery(Stringsql){ResultSetrs=null;Statementstmt=null;if(conn==null){this.getConnection();}try{stmt=conn.createStatement();rs=stmt.executeQuery(sql);returnrs;}catch(SQLExceptione){returnnull;}}publicintexecuteUpdate(Stringsql){Statementstmt=null;intlinecount=0;if(conn==null){this.getConnection();}try{stmt=conn.createStatement();linecount=stmt.executeUpdate(sql);}catch(SQLExceptione){}returnlinecount;}}packageexp10;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.ResultSet;importjava.sql.SQLException;importjavax.swing.Box;importjavax.swing.ButtonGroup;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JRadioButton;importjavax.swing.JTextField;publicclassLoginPaneextendsJPanelimplementsActionListener{/****/privatestaticfinallongserialVersionUID=1L;JFramemyFrame;JLabellab_username=newJLabel(用户名);JTextFieldjt_username=newJTextField(20);JLabellab_password=newJLabel(密码);JPasswordFieldjt_pwd=newJPasswordField(20);JRadioButtonjrb_manager=newJRadioButton(管理员);JRadioButtonjrb_teacher=newJRadioButton(教师);JRadioButtonjrb_student=newJRadioButton(学生);publicLoginPane(JFramemyFrame){this.myFrame=myFrame;this.init();}publicvoidinit(){Boxbox_user=Box.createHorizontalBox();box_user.add(lab_username);box_user.add(Box.createHorizontalStrut(20));box_user.add(jt_username);jt_pwd.setEchoChar('#');Boxbox_pwd=Box.createHorizontalBox();box_pwd.add(lab_password);box_pwd.add(Box.createHorizontalStrut(20));box_pwd.add(jt_pwd);ButtonGroupbg=newButtonGroup();bg.add(jrb_manager);bg.add(jrb_teacher);bg.add(jrb_student);Boxbox_role=Box.createHorizontalBox();box_role.add(jrb_manager);box_role.add(Box.createHorizontalStrut(5));box_role.add(jrb_teacher);box_role.add(Box.createHorizontalStrut(5));box_role.add(jrb_student);JButtonjb_login=newJButton(登陆);JButtonjb_exit=newJButton(退出);Boxbox_button=Box.createHorizontalBox();box_button.add(jb_login);box_button.add(Box.createHorizontalStrut(30));box_button.add(jb_exit);jb_login.addActionListener(this);jb_exit.addActionListener(this);jb_login.setActionCommand(login);jb_exit.setActionCommand(exit);Boxbox_login=Box.createVerticalBox();box_login.add(box_user);box_login.add(Box.createHorizontalStrut(10));box_login.add(box_pwd);box_login.add(Box.createHorizontalStrut(10));box_login.add(box_role);box_login.add(Box.createHorizontalStrut(10));box_login.add(box_button);this.add(box_login);}@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubif(e.getActionCommand().equals(login)){Stringusername=this.jt_username.getText().trim();Stringpwd=String.valueOf(this.jt_pwd.getPassword());DataBasedb=newDataBase();Stringsql=select*fromUserwherename='+username+'andpassword='+pwd+';ResultSetrs=db.executeQuery(sql);if(rs!=null){this.myFrame.setContentPane(newManagerPane(this.myFrame));myFrame.setSize(800,500);this.myFrame.validate();}}else{this.myFrame.dispose();}}}packageexp10;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.ItemEvent;importjava.awt.event.ItemListener;importjavax.swing.JFrame;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;importjavax.swing.JPanel;importjavax.swing.JTable;publicclassManagerPaneextendsJPanelimplementsActionListener{JFramemyFrame;publicManagerPane(JFramemyFrame){this.myFrame=myFrame;this.init();}publicvoidinit(){JMenuBarmenu=newJMenuBar();JMenujm_user=newJMenu(人员管理);JMenuItemjmi_add=newJMenuItem(增加人员);JMenuItemjmi_search=newJMenuItem(查询人员);jmi_add.addActionListener(this);jmi_add.setActionCommand(addUser);jmi_search.addActionListener(this);jmi_search.setActionCommand(searchUser);jm_user.add(jmi_add);jm_user.add(jmi_search);JMenujm_exit=newJMenu(退出);menu.add(jm_user);menu.add(jm_exit);this.add(menu,0);}@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubif(e.getActionCommand().equals(searchUser)){this.myFrame.setContentPane(newSearchUserPane(this.myFrame));this.myFrame.validate(

1 / 19
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功