java+数据库教室管理系统代码.docx

上传人:b****6 文档编号:7321776 上传时间:2023-01-22 格式:DOCX 页数:114 大小:25.97KB
下载 相关 举报
java+数据库教室管理系统代码.docx_第1页
第1页 / 共114页
java+数据库教室管理系统代码.docx_第2页
第2页 / 共114页
java+数据库教室管理系统代码.docx_第3页
第3页 / 共114页
java+数据库教室管理系统代码.docx_第4页
第4页 / 共114页
java+数据库教室管理系统代码.docx_第5页
第5页 / 共114页
点击查看更多>>
下载资源
资源描述

java+数据库教室管理系统代码.docx

《java+数据库教室管理系统代码.docx》由会员分享,可在线阅读,更多相关《java+数据库教室管理系统代码.docx(114页珍藏版)》请在冰豆网上搜索。

java+数据库教室管理系统代码.docx

java+数据库教室管理系统代码

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);

}

@Override

publicvoidactionPerformed(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;

}

@Override

protectedvoidprocessWindowEvent(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;

//主控制界面

privateJPanel

//topBar

topBar,rightBar;

userName;

privateJLabel

privateJButton

//rightBar

quit;

privateJPanel

privateJLabel

privateJComboBox

privateJButton

operationP,buttonP,searchP;

operationT,search;

operation;

searchB,alert,insert,delete;

privateJTextFieldsearchT;//搜索字样

//centerBar

private

private

JScrollPanescroll;

JTable

content;

privateMyTableModelmodel;

privateString[]list=newString[]{"

"};

教师信息","教室信息","教室使用情况","教室具体使用情况

privateJLabelremind;

publicstaticvoidmain(String[]args)

{

newControlInterface();

}

publicControlInterface()

{

//登录界面--------------------------------------------

login=newLogin(this,"登录",true);

//登陆界面回来之后

//topBar

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.setActionCommand("quit");

quit.addActionListener(this);

quit.setLocation((int)(this.getWidth()-quit.getWidth()*1.5),userName.getHeight()/3);

topBar.add(quit,BorderLayout.EAST);

this.add(topBar,BorderLayout.NORTH);

//rightBar

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(){

@Override

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);

searchT.setText("请输入"+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);

//centerBar

model=newMyTableModel(operation.getSelectedItem().toString());

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.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

@Override

publicvoidactionPerformed(ActionEventarg0){

if(arg0.getActionCommand()=="quit")

{

}

System.exit(0);

if(arg0.getActionCommand()=="search")

{

search2UnionTable();

return;

}

if(((String)operation.getSelectedItem())=="教室具体使用情况

")

{

newRemindDialog(this,"提示",true,0);

return;

}

if(arg0.getActionCommand()=="insert")

{

newInsert(this,"增加新数据",true,operation.getSelectedItem().toString());

model=newMyTableModel(operation.getSelectedItem().toString());

content.setModel(model);

return;

}

if(content.getSelectedRow()==-1)

{

newRemindDialog(this,"提示",true,1);

return;

}

if(arg0.getActionCommand()=="alert")

{

Vectorv=(Vector)MyTableModel.rowData.get(content.getSelectedRow());

newUpdate(this,"修改",true,operation.getSelectedItem().toString(),v);

model=newMyTableModel(operation.getSelectedItem().toString());

content.setModel(model);

return;

}

if(arg0.getActionCommand()=="delete")

{

Vectorv=(Vector)MyTableModel.rowData.get(content.getSelectedRow());

newDelete(this,"删除",true,v,operation.getSelectedItem().toString());

model=newMyTableModel(operation.getSelectedItem().toString());

content.setModel(model);

return;

}

}

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("-----无该教室信息-----");

return;

}else

{

remind.setText("");

}

MyTableModelmy=newMyTableModel(rowData,MyTableModel.columnNames);

content.setModel(my);

}

}

4.向主界面中加载数据

packagedev.chall.util;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.SQL

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1