教室管理系统的源代码

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

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

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

资源描述

1.创建数据库CreatedatebaseclassManager;createtableClassInfo(教室编号varchar(10)primarykey,教室设备varchar(100)notnull,教室容纳人数intnotnull,教室管理员编号varchar(10)notnull);createtableTeacherInfo(教师编号varchar(10)primarykey,教师姓名varchar(20)notnull,教授课程varchar(50),教师职称varchar(20)notnull);createtableClassRoomInfo(教室编号varchar(10),上课开始时间dateTimenotnull,结束时间dateTimenotnull,教师编号varchar(10),Foreignkey(教室编号)referencesClassInfo(教室编号),Foreignkey(教师编号)referencesTeacherInfo(教师编号));createtablemanager(usernamevarchar(10)notnull,userpswvarchar(10)notnull);向其中插入数据。insertClassInfovalues('4101','投影仪','40','01')insertClassInfovalues('4102','电脑','50','02')insertTeacherInfovalues('0A','李萍','计算机系统分','讲师')insertTeacherInfovalues('0B','李明','C语言','教授')insertClassRoomInfovalues('4101','8:00','10:00','0A')insertClassRoomInfovalues('4102','10:00','12:00','0B')insertmanagervalues('jack','20120521')2.创建登录界面packagedev.chall.otherinterface;importjava.awt.Cursor;importjava.awt.FlowLayout;importjava.awt.Frame;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowEvent;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjavax.swing.JButton;importjavax.swing.JDialog;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTextField;publicclassLoginextendsJDialogimplementsActionListener{privateJLabelname;privateJLabelpsw;privateJTextFieldnameV;privateJPasswordFieldpswV;privateJButtonlogin,quit;privateJPaneltop;privateJPanelcenter;privateJPanelbottom;privateJLabelprompt;publicstaticStringloginName;publicLogin(Frameowner,Stringtitle,booleanmodal){super(owner,title,modal);init();}privatevoidinit(){name=newJLabel(登录名:);nameV=newJTextField(10);top=newJPanel();top.add(name);top.add(nameV);this.add(top);psw=newJLabel(密码:);pswV=newJPasswordField(10);center=newJPanel();center.add(psw);center.add(pswV);this.add(center);login=newJButton();login.setText(登录);login.setActionCommand(login);login.addActionListener(this);quit=newJButton(退出);quit.setActionCommand(quit);quit.addActionListener(this);bottom=newJPanel();bottom.add(login);bottom.add(quit);this.add(bottom);prompt=newJLabel();this.add(prompt);this.setLayout(newGridLayout(4,1));this.setLocation(550,230);this.setSize(200,200);this.setVisible(true);}@OverridepublicvoidactionPerformed(ActionEventarg0){if(arg0.getActionCommand()==login){Stringname=nameV.getText();Stringpsw=pswV.getText();if(name.length()=0||psw.length()=0){prompt.setText(提示:用户名或密码为空!);return;}if(checkCount(name,psw)){this.dispose();}else{prompt.setText(提示:用户名或密码错误!);return;}}elseif(arg0.getActionCommand()==quit){System.exit(0);}}privatebooleancheckCount(Stringname,Stringpsw){Connectionconnection=null;PreparedStatementps=null;ResultSetrs=null;try{//加载驱动Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);//得到连接connection=DriverManager.getConnection(jdbc:odbc:classManager,sa,songchao);//创建访问数据库接口ps=connection.prepareStatement(select*frommanager);rs=ps.executeQuery();while(rs.next()){Stringnamet=rs.getString(1);Stringpswt=rs.getString(2);System.out.println(namet++pswt+-------+name++psw+---);if(namet.equals(name)&&pswt.equals(psw)){loginName=namet;returntrue;}}System.out.println(false);}catch(Exceptione){e.printStackTrace();}finally{try{rs.close();ps.close();connection.close();}catch(SQLExceptione){e.printStackTrace();}}returnfalse;}@OverrideprotectedvoidprocessWindowEvent(WindowEventarg0){super.processWindowEvent(arg0);if(arg0.getID()==WindowEvent.WINDOW_CLOSING){System.exit(0);}}}3.实现主界面,实现各按钮的作用packagedev.chall.main;importjava.awt.BorderLayout;importjava.awt.FlowLayout;importjava.awt.Font;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.ItemEvent;importjava.awt.event.ItemListener;importjava.awt.event.WindowEvent;importjava.util.Iterator;importjava.util.Vector;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JDialog;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JScrollBar;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.JTextField;importdev.chall.otherinterface.Delete;importdev.chall.otherinterface.Insert;importdev.chall.otherinterface.Update;importdev.chall.otherinterface.Login;importdev.chall.otherinterface.RemindDialog;importdev.chall.util.MyTableModel;publicclassControlInterfaceextendsJFrameimplementsActionListener{//登录界面Loginlogin;//主控制界面privateJPaneltopBar,rightBar;//topBarprivateJLabeluserName;privateJButtonquit;//rightBarprivateJPaneloperationP,buttonP,searchP;privateJLabeloperationT,search;privateJComboBoxoperation;privateJButtonsearchB,alert,insert,delete;privateJTextFieldsearchT;//搜索字样//centerBarprivateJScrollPanescroll;privateJTablecontent;privateMyTableModelmodel;privateString[]list=newString[]{教师信息,教室信息,教室使用情况,教室具体使用情况};privateJLabelremind;publicstaticvoidmain(String[]args){newControlInterface()

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

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

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

×
保存成功