学生管理系统图形界面JavaWord文件下载.docx
- 文档编号:17055955
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:13
- 大小:16.73KB
学生管理系统图形界面JavaWord文件下载.docx
《学生管理系统图形界面JavaWord文件下载.docx》由会员分享,可在线阅读,更多相关《学生管理系统图形界面JavaWord文件下载.docx(13页珍藏版)》请在冰豆网上搜索。
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-generatedcatchblock
e.printStackTrace();
}
publicResultSetexecuteQuery(Stringsql){
ResultSetrs=null;
Statementstmt=null;
if(conn==null){
this.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
returnrs;
returnnull;
publicintexecuteUpdate(Stringsql){
intlinecount=0;
linecount=stmt.executeUpdate(sql);
}catch(SQLExceptione){}
returnlinecount;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.Box;
importjavax.swing.ButtonGroup;
importjavax.swing.JButton;
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(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_role);
box_login.add(box_button);
this.add(box_login);
@Override
publicvoidactionPerformed(ActionEvente){
if(e.getActionCommand().equals("
)){
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();
importjava.awt.event.ItemEvent;
importjava.awt.event.ItemListener;
importjavax.swing.JMenu;
importjavax.swing.JMenuBar;
importjavax.swing.JMenuItem;
importjavax.swing.JTable;
publicclassManagerPaneextendsJPanelimplementsActionListener{
publicManagerPane(JFramemyFrame){
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);
this.myFrame.setContentPane(newSearchUserPane(this.myFrame));
this.myFrame.validate();
importjava.util.Vector;
importjavax.swing.table.DefaultTableModel;
publicclassSearchUserPaneextendsJPanelimplementsActionListener{
JLabeljlb_name=newJLabel("
查询用户名"
JTextFieldjt_name=newJTextField(20);
JButtonbtn_search=newJButton("
查询"
DataBasedb=newDataBase();
DefaultTableModeltableModel;
JTablejt_show;
publicSearchUserPane(JFramemyFrame){
init();
box_user.add(jlb_name);
box_user.add(jt_name);
btn_search.addActionListener(this);
box_user.add(btn_search);
String[]colname={"
编号"
"
姓名"
密码"
身份"
};
tableModel=newDefaultTableModel(null,colname);
jt_show=newJTable(tableModel);
Boxbox_show=Box.createHorizontalBox();
box_show.add(jt_show);
ResultSetrs=db.executeQuery("
select*fromUser"
try{
while(rs.next()){
Vectordata=newVector();
data.add(rs.getString("
id"
));
name"
password"
role"
tableModel.addRow(data);
}catch(SQLExceptione){
Boxbox_search=Box.createVerticalBox();
box_search.add(box_user);
box_search.add(Box.createVerticalStrut(50));
box_search.add(box_show);
this.add(box_search);
if(e.getSource()==this.btn_search){
Stringusername=this.jt_name.getText().trim();
ResultSetrs=db.executeQuery("
try{
while(rs.next()){
Vectordata=newVector();
data.add(rs.getString("
tableModel.fireTableDataChanged();
tableModel.addRow(data);
}
}catch(SQLExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
publicclassUserTableextendsJTable{
publicUserTable(){
importjava.sql.ResultSetMetaData;
importjavax.swing.table.AbstractTableModel;
publicclassUserTableModelextendsAbstractTableModel{
ResultSetrs;
Vectortabledat;
publicUserTableModel(){
DataBasedb=newDataBase();
rs=db.executeQuery("
tabledat=newVector();
publicintgetColumnCount(){
ResultSetMetaDatametadata=rs.getMetaData();
returnmetadata.getColumnCount();
return0;
publicintgetRowCount(){
intrownum=0;
rownum++;
returnrownum;
publicObjectgetValueAt(introw,intcol){
if(rs.absolute(row)){
returnrs.getObject(col);
re
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 管理 系统 图形界面 Java
![提示](https://static.bdocx.com/images/bang_tan.gif)