java+数据库教室管理系统代码Word文档下载推荐.docx
《java+数据库教室管理系统代码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《java+数据库教室管理系统代码Word文档下载推荐.docx(114页珍藏版)》请在冰豆网上搜索。
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);
@Override
publicvoidactionPerformed(ActionEventarg0){
if(arg0.getActionCommand()=="
)
Stringname=nameV.getText();
Stringpsw=pswV.getText();
if(name.length()<
=0||psw.length()<
=0)
prompt.setText("
提示:
用户名或密码为空!
return;
if(checkCount(name,psw))
this.dispose();
}else
用户名或密码错误!
}elseif(arg0.getActionCommand()=="
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{
rs.close();
ps.close();
connection.close();
}catch(SQLExceptione){
returnfalse;
protectedvoidprocessWindowEvent(WindowEventarg0){
super.processWindowEvent(arg0);
if(arg0.getID()==WindowEvent.WINDOW_CLOSING)
3.实现主界面,实现各按钮的作用
packagedev.chall.main;
importjava.awt.BorderLayout;
importjava.awt.Font;
importjava.awt.event.ItemEvent;
importjava.awt.event.ItemListener;
importjava.util.Iterator;
importjava.util.Vector;
importjavax.swing.JComboBox;
importjavax.swing.JFrame;
importjavax.swing.JScrollBar;
importjavax.swing.JScrollPane;
importjavax.swing.JTable;
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;
//主控制界面
privateJPanel
//topBar
topBar,rightBar;
userName;
privateJLabel
privateJButton
//rightBar
quit;
privateJComboBox
operationP,buttonP,searchP;
operationT,search;
operation;
searchB,alert,insert,delete;
privateJTextFieldsearchT;
//搜索字样
//centerBar
private
JScrollPanescroll;
JTable
content;
privateMyTableModelmodel;
privateString[]list=newString[]{"
};
教师信息"
"
教室信息"
教室使用情况"
教室具体使用情况
privateJLabelremind;
publicstaticvoidmain(String[]args)
newControlInterface();
publicControlInterface()
//登录界面--------------------------------------------
login=newLogin(this,"
true);
//登陆界面回来之后
topBar
=
newJPanel();
newJLabel();
userName
userName.setText(Login.loginName);
userName.setFont(newFont("
隶书"
1,25));
//字体,1代表样式,字号
userName.setLocation(this.getWidth()/2-userName.getWidth()/2,
userName.getHeight()/3);
topBar.add(userName,BorderLayout.CENTER);
quit
newJButton("
quit.setLocation((int)(this.getWidth()-quit.getWidth()*1.5),userName.getHeight()/3);
topBar.add(quit,BorderLayout.EAST);
this.add(topBar,BorderLayout.NORTH);
rightBar=newJPanel();
rightBar.setLayout(newGridLayout(4,1));
this.add(rightBar,BorderLayout.EAST);
operationP=newJPanel();
operationP.setLayout(newFlowLayout());
operationT=newJLabel("
选择表:
"
operation=newJComboBox(list);
operation.addItemListener(newItemListener(){
publicvoiditemStateChanged(ItemEventarg0){
searchT.setText("
请输入"
+
operation.getSelectedItem().toString().substring(0,2)+"
编号"
model=newMyTableModel(operation.getSelectedItem().toString());
content.setModel(model);
});
operationP.add(operationT);
operationP.add(operation);
buttonP=newJPanel();
buttonP.setLayout(newGridLayout(3,1));
alert=newJButton("
修改"
alert.addActionListener(this);
alert.setActionCommand("
alert"
insert=newJButton("
增加"
insert.addActionListener(this);
insert.setActionCommand("
insert"
delete=newJButton("
删除"
delete.addActionListener(this);
delete.setActionCommand("
delete"
buttonP.add(alert);
buttonP.add(insert);
buttonP.add(delete);
operationP.add(buttonP);
rightBar.add(operationP);
search=newJLabel("
关键字:
searchT=newJTextField(10);
+operation.getSelectedItem().toString().substring(0,2)+"
编号
searchB=newJButton("
搜索"
searchB.addActionListener(this);
searchB.setActionCommand("
search"
searchP=newJPanel();
searchP.setLayout(newFlowLayout());
searchP.add(search);
searchP.add(searchT);
searchP.add(searchB);
rightBar.add(searchP);
remind=newJLabel();
rightBar.add(remind);
content=newJTable(model);
scroll=newJScrollPane(content);
this.add(scroll,BorderLayout.CENTER);
this.setTitle("
教室管理系统"
this.setResizable(false);
this.setLocation(180,60);
this.setSize(1000,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
search2UnionTable();
if(((String)operation.getSelectedItem())=="
newRemindDialog(this,"
提示"
true,0);
newInsert(this,"
增加新数据"
true,operation.getSelectedItem().toString());
if(content.getSelectedRow()==-1)
true,1);
Vectorv=(Vector)MyTableModel.rowData.get(content.getSelectedRow());
newUpdate(this,"
true,operation.getSelectedItem().toString(),v);
Vectorv=(Vector)MyTableModel.rowData.get(content.getSelectedRow());
newDelete(this,"
true,v,operation.getSelectedItem().toString());
privatevoidsearch2UnionTable()
Vectorv=MyTableModel.select(operation.getSelectedItem().toString());
VectorrowData=newVector();
Iteratoriterator=v.iterator();
StringrNum=searchT.getText().toString().trim();
while(iterator.hasNext())
Vectortem=(Vector)iterator.next();
if(((String)tem.get(0)).equals(rNum))
rowData.add(tem);
if(rowData.size()==0)
remind.setText("
-----无该教室信息-----"
MyTableModelmy=newMyTableModel(rowData,MyTableModel.columnNames);
content.setModel(my);
4.向主界面中加载数据
packagedev.chall.util;
importjava.sql.SQL