您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 计算机应用/办公自动化 > 教室管理系统的源代码
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);向其中插入数据。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();}publicControlInterface(){//登录界面--------------------------------------------login=newLogin(this,登录,true);//登陆界面回来之后//topBartopBar=newJPanel();userName=newJLabel();userName.setText(Login.loginName);userName.setFont(newFont(隶书,1,25));//字体,1代表样式,字号userName.setLocation(this.getWidth()/2-userName.getWidth()/2,userName.getHeight()
本文标题:教室管理系统的源代码
链接地址:https://www.777doc.com/doc-1006136 .html