




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1.创建数据库Create datebase classManager;create table ClassInfo(教室编号 varchar(10) primary key,教室设备 varchar(100) not null,教室容纳人数 int not null,教室管理员编号 varchar(10) not null);create table TeacherInfo(教师编号 varchar(10) primary key,教师姓名varchar(20) not null,教授课程varchar(50),教师职称 varchar(20) not null);create table
2、ClassRoomInfo(教室编号 varchar(10),上课开始时间 dateTime not null,结束时间 dateTime not null,教师编号 varchar(10),Foreign key (教室编号) references ClassInfo(教室编号), Foreign key (教师编号) references TeacherInfo(教师编号);create table manager(username varchar(10) not null,userpsw varchar(10) not null);向其中插入数据。insert ClassInfovalu
3、es('4101','投影仪','40','01')insert ClassInfovalues('4102','电脑','50','02')insert TeacherInfovalues('0A','李萍','计算机系统分','讲师')insert TeacherInfovalues('0B','李明','C语言','教授')insert
4、 ClassRoomInfovalues('4101','8:00','10:00','0A')insert ClassRoomInfovalues('4102','10:00','12:00','0B')insert managervalues('jack','20120521')2.创建登录界面package dev.chall.otherinterface;import java.awt.Cursor;import java.aw
5、t.FlowLayout;import java.awt.Frame;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowEvent;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.
6、SQLException;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Login extends JDialog implements ActionListenerprivate JLabel name;private JLabel psw;private JTextField
7、 nameV;private JPasswordField pswV;private JButton login,quit;private JPanel top;private JPanel center;private JPanel bottom;private JLabel prompt;public static String loginName;public Login(Frame owner, String title, boolean modal) super(owner, title, modal);init();private void init()name=new JLabe
8、l("登录名:");nameV=new JTextField(10);top=new JPanel();top.add(name);top.add(nameV);this.add(top);psw=new JLabel("密 码:");pswV=new JPasswordField(10);center=new JPanel();center.add(psw);center.add(pswV);this.add(center);login=new JButton();login.setText("登录");login.setActio
9、nCommand("login");login.addActionListener(this);quit=new JButton("退出");quit.setActionCommand("quit");quit.addActionListener(this);bottom=new JPanel();bottom.add(login);bottom.add(quit);this.add(bottom);prompt=new JLabel();this.add(prompt);this.setLayout(new GridLayout(4
10、, 1);this.setLocation(550, 230);this.setSize(200,200);this.setVisible(true);Overridepublic void actionPerformed(ActionEvent arg0) if(arg0.getActionCommand()="login")String name=nameV.getText();String psw=pswV.getText();if(name.length()<=0|psw.length()<=0)prompt.setText("提示:用户名或密
11、码为空!");return;if(checkCount(name,psw)this.dispose();elseprompt.setText("提示:用户名或密码错误!");return;else if(arg0.getActionCommand()="quit")System.exit(0);private boolean checkCount(String name,String psw)Connection connection=null;PreparedStatement ps=null;ResultSet rs=null;try /加
12、载驱动Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");/得到连接connection=DriverManager.getConnection("jdbc:odbc:classManager", "sa", "songchao");/创建访问数据库接口ps=connection.prepareStatement("select * from manager");rs=ps.executeQuery();while(rs.next()String name
13、t=rs.getString(1);String pswt=rs.getString(2);System.out.println(namet+"<>"+pswt+"-"+name+"<>"+psw+"-");if(namet.equals(name)&&pswt.equals(psw)loginName=namet;return true;System.out.println("false"); catch (Exception e) e.printSta
14、ckTrace();finallytry rs.close();ps.close();connection.close(); catch (SQLException e) e.printStackTrace();return false;Overrideprotected void processWindowEvent(WindowEvent arg0) cessWindowEvent(arg0);if(arg0.getID()=WindowEvent.WINDOW_CLOSING)System.exit(0);3.实现主界面,实现各按钮的作用package dev.chal
15、l.main;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowEvent;import java.util.
16、Iterator;import java.util.Vector;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.
17、JTextField; import dev.chall.otherinterface.Delete;import dev.chall.otherinterface.Insert;import dev.chall.otherinterface.Update;import dev.chall.otherinterface.Login;import dev.chall.otherinterface.RemindDialog;import dev.chall.util.MyTableModel;public class ControlInterface extends JFrame implemen
18、ts ActionListener/登录界面Login login;/主控制界面private JPanel topBar,rightBar;/topBarprivate JLabel userName;private JButtonquit;/rightBarprivate JPanel operationP,buttonP,searchP;private JLabel operationT,search;private JComboBox operation;private JButton searchB,alert,insert,delete;private JTextFieldsear
19、chT;/搜索字样 /centerBarprivateJScrollPane scroll;privateJTable content;private MyTableModel model;private String list=new String"教师信息","教室信息","教室使用情况","教室具体使用情况"private JLabel remind;public static void main(String args)new ControlInterface();public ControlInterfa
20、ce()/登录界面 -login=new Login(this, "登录",true);/登陆界面回来之后/topBartopBar=new JPanel();userName=new JLabel();userName.setText(Login.loginName);userName.setFont(new Font("隶书",1,25);/字体,1代表样式,字号userName.setLocation(this.getWidth()/2-userName.getWidth()/2, userName.getHeight()/3);topBar.ad
21、d(userName,BorderLayout.CENTER);quit=new JButton("退出");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);/rightBarri
22、ghtBar=new JPanel();rightBar.setLayout(new GridLayout(4,1);this.add(rightBar,BorderLayout.EAST);operationP=new JPanel();operationP.setLayout(new FlowLayout();operationT=new JLabel("选择表:");operation=new JComboBox(list);operation.addItemListener(new ItemListener()Overridepublic void itemStat
23、eChanged(ItemEvent arg0) searchT.setText("请输入"+ operation.getSelectedItem().toString().substring(0,2)+ "编号");model=new MyTableModel(operation.getSelectedItem().toString();content.setModel(model);) ;operationP.add(operationT);operationP.add(operation);buttonP=new JPanel();buttonP.
24、setLayout(new GridLayout(3,1);alert=new JButton("修改");alert.addActionListener(this);alert.setActionCommand("alert");insert=new JButton("增加");insert.addActionListener(this);insert.setActionCommand("insert");delete=new JButton("删除");delete.addActionLis
25、tener(this);delete.setActionCommand("delete");buttonP.add(alert);buttonP.add(insert);buttonP.add(delete);operationP.add(buttonP);rightBar.add(operationP);search=new JLabel("关键字:");searchT=new JTextField(10);searchT.setText("请输入"+operation.getSelectedItem().toString().su
26、bstring(0,2)+"编号");searchB=new JButton("搜索");searchB.addActionListener(this);searchB.setActionCommand("search");searchP=new JPanel();searchP.setLayout(new FlowLayout();searchP.add(search);searchP.add(searchT);searchP.add(searchB);rightBar.add(searchP);remind=new JLabel(
27、);rightBar.add(remind);/centerBarmodel=new MyTableModel(operation.getSelectedItem().toString();content=new JTable(model);scroll=new JScrollPane(content);this.add(scroll,BorderLayout.CENTER);this.setTitle("教室管理系统");this.setResizable(false);this.setLocation(180,60);this.setSize(1000, 600);th
28、is.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Overridepublic void actionPerformed(ActionEvent arg0) if(arg0.getActionCommand()="quit")System.exit(0);if(arg0.getActionCommand()="search")search2UnionTable();return;if(String)operation.getSelectedItem()=&quo
29、t;教室具体使用情况")new RemindDialog(this, "提示",true,0);return;if(arg0.getActionCommand()="insert")new Insert(this,"增加新数据",true,operation.getSelectedItem().toString();model=new MyTableModel(operation.getSelectedItem().toString();content.setModel(model);return;if(content.ge
30、tSelectedRow()=-1)new RemindDialog(this, "提示",true,1);return;if(arg0.getActionCommand()="alert")Vector v=(Vector)MyTableModel.rowData.get(content.getSelectedRow();new Update(this,"修改",true,operation.getSelectedItem().toString(),v);model=new MyTableModel(operation.getSel
31、ectedItem().toString();content.setModel(model);return;if(arg0.getActionCommand()="delete")Vector v=(Vector) MyTableModel.rowData.get(content.getSelectedRow();new Delete(this,"删除",true,v,operation.getSelectedItem().toString();model=new MyTableModel(operation.getSelectedItem().toSt
32、ring();content.setModel(model);return;private void search2UnionTable()Vector v=MyTableModel.select(operation.getSelectedItem().toString();Vector rowData=new Vector();Iterator iterator=v.iterator();String rNum=searchT.getText().toString().trim();while(iterator.hasNext()Vector tem=(Vector)iterator.nex
33、t();if(String)tem.get(0).equals(rNum)rowData.add(tem);if(rowData.size()=0)remind.setText("-无该教室信息-");return;elseremind.setText("");MyTableModel my=new MyTableModel(rowData,MyTableModel.columnNames);content.setModel(my);4.向主界面中加载数据package dev.chall.util;import java.sql.Connection;
34、import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;import javax.swing.table.AbstractTableModel;public class MyTableModel extends AbstractTableModelpublic static Vector rowData;public static Vector columnNames
35、;public MyTableModel(String value) select(value);public MyTableModel(Vector rowData,Vector columnNames) this.rowData=rowData;this.columnNames=columnNames;public static Vector select(String value)rowData=new Vector();columnNames=new Vector();Connection connection=null;PreparedStatement ps=null;Result
36、Set rs=null;String sql = null;if(value="教师信息")columnNames.add("教师编号");columnNames.add("教师姓名");columnNames.add("教授课程");columnNames.add("教师职称");sql="select * from TeacherInfo"else if(value="教室信息")columnNames.add("教室编号");co
37、lumnNames.add("教室设备");columnNames.add("教室容纳人数");columnNames.add("教室管理员编号");sql="select * from ClassInfo"else if(value="教室使用情况")columnNames.add("教室编号");columnNames.add("上课开始时间");columnNames.add("结束时间");columnNames.add(&qu
38、ot;教师编号");sql="select 教室编号, convert(varchar(20),上课开始时间,111),convert(varchar(20),上课开始时间,108),convert(varchar(20),结束时间,111) ,convert(varchar(20),结束时间,108), 教师编号 from ClassRoomInfo"else if(value="教室具体使用情况")columnNames.add("教室编号");columnNames.add("教师编号");colu
39、mnNames.add("教师姓名");columnNames.add("教授课程");columnNames.add("上课开始时间"); columnNames.add("结束时间");columnNames.add("教师职称");columnNames.add("教室设备");columnNames.add("教室容纳人数");columnNames.add("教室管理员编号");sql="select ClassIn
40、fo.教室编号,TeacherInfo.教师编号,TeacherInfo.教师姓名,TeacherInfo.教授课程, convert(varchar(20),ClassRoomInfo.上课开始时间,111),convert(varchar(20),ClassRoomInfo.上课开始时间,108),convert(varchar(20),ClassRoomInfo.结束时间,111) ,convert(varchar(20),ClassRoomInfo.结束时间,108) ,TeacherInfo.教师职称,ClassInfo.教室设备,ClassInfo.教室容纳人数,ClassInfo
41、.教室管理员编号 from ClassRoomInfo,TeacherInfo,ClassInfo where ClassInfo.教室编号= ClassRoomInfo.教室编号 and TeacherInfo.教师编号=ClassRoomInfo.教师编号"try /加载驱动Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");/得到连接 connection=DriverManager.getConnection("jdbc:odbc:classManager", "sa", &q
42、uot;songchao");/创建访问数据库接口ps=connection.prepareStatement(sql);rs=ps.executeQuery();if(value="教师信息")while(rs.next()Vector tem=new Vector();tem.add(rs.getString(1);tem.add(rs.getString(2);tem.add(rs.getString(3);tem.add(rs.getString(4);rowData.add(tem);else if(value="教室信息")whil
43、e(rs.next()Vector tem=new Vector();tem.add(rs.getString(1);tem.add(rs.getString(2);tem.add(rs.getInt(3);tem.add(rs.getString(4);rowData.add(tem);else if(value="教室使用情况")while(rs.next()Vector tem=new Vector();tem.add(rs.getString(1);tem.add(rs.getString(2)+"/"+rs.getString(3);tem.a
44、dd(rs.getString(4)+"/"+rs.getString(5);tem.add(rs.getString(6);rowData.add(tem);else if(value="教室具体使用情况")while(rs.next()Vector tem=new Vector();tem.add(rs.getString(1);tem.add(rs.getString(2);tem.add(rs.getString(3);tem.add(rs.getString(4);tem.add(rs.getString(5)+"/"+rs
45、.getString(6);tem.add(rs.getString(7)+"/"+rs.getString(8);tem.add(rs.getString(9);tem.add(rs.getString(10);tem.add(rs.getInt(11);tem.add(rs.getString(12);rowData.add(tem); catch (Exception e) e.printStackTrace();finallytry rs.close();ps.close();connection.close(); catch (SQLException e) e.
46、printStackTrace();return rowData;Overridepublic String getColumnName(int arg0) return (String) columnNames.get(arg0);Overridepublic int getColumnCount() return columnNames.size();Overridepublic int getRowCount() return rowData.size();Override public Object getValueAt(int rowIndex, int columnIndex) r
47、eturn (Vector)rowData.get(rowIndex).get(columnIndex);5.实现主界面中修改按钮功能package dev.chall.otherinterface;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;impo
48、rt java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.Vector;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel
49、;import javax.swing.JTextField;import dev.chall.util.MyTableModel;public class Update extends JDialogprivate JLabel warn=new JLabel();/提示文本private JButton sure=new JButton("-确定-");private JButton cancle=new JButton("-取消-");private String sql;final JTextField t51=new JTextField(15
50、);final JTextField t52=new JTextField(15);final JTextField t53=new JTextField(15);final JTextField t54=new JTextField(15);public Update(Frame owner, String title, boolean modal,String name,final Vector v) super(owner, title, modal);warn.setBounds(0, 0, 300, 50);t51.setText(v.get(0).toString();t51.se
51、tEditable(false);t52.setText(v.get(1).toString();t53.setText(v.get(2).toString();t54.setText(v.get(3).toString();if(name="教师信息")JLabel t1=new JLabel("教师编号:");JLabel t2=new JLabel("教师姓名:");JLabel t3=new JLabel("教授课程:");JLabel t4=new JLabel("教师职称:");su
52、re.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) String tNum=t51.getText();String tName=t52.getText().trim();String tCourse=t53.getText().trim();String tTitle=t54.getText().trim();if(tNum.length()<=0|tName.length()<=0|tCourse.length()<=0|tTitle.len
53、gth()<=0)warn.setText("-信息不全-");return;sql="UPDATE TeacherInfo SET 教师姓名='"+tName+"',教授课程 ='"+tCourse+"',教师职称='"+tTitle+"' WHERE 教师编号 = '"+tNum+"'"update2Table(sql);Update.this.dispose(););cancle.addActionL
54、istener(new ActionListener()Overridepublic void actionPerformed(ActionEvent e) Update.this.dispose(););this.add(t1);this.add(t51);this.add(t2);this.add(t52);this.add(t3);this.add(t53);this.add(t4);this.add(t54);this.add(sure);this.add(cancle);this.add(warn);this.setLayout(new FlowLayout();this.setSize(250,300);this.setLocation(550, 100);this.setResizable(false);this.setVisible(true);this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);else if(name="教室信息")JLabel t1=new JLabel(" 教 室 编 号:");JLabel t2=new JLab
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届河北省石家庄市普通高中化学高二上期中监测试题含解析
- 多语宝宝:如何高效利用黄金期
- 香格里拉酒店面试题及答案
- 颜料绘画测试题及答案
- java数据结构面试题及答案顺序表
- 家电公司降级降职管理办法
- 家电公司生产设备管理细则
- 小学数学六年级上册-期末口算题专项突破练习(含答案)北师大版
- 2022年河北省唐山一中(唐山市)高三下学期二模考试英语试题
- 室内物业绿化管理方案(3篇)
- 兰花花叙事曲二胡曲谱
- 调解协议书电子版5篇(可下载)
- 材料性能学(第2版)付华课件1-弹性变形
- GB/T 4909.4-2009裸电线试验方法第4部分:扭转试验
- PDCA质量持续改进案例一:降低ICU非计划拔管发生率
- 2023年烟台蓝天投资开发集团有限公司招聘笔试题库及答案解析
- 企业标准编写模板
- 初中道德与法治 九年级(维护祖国统一)初中道德与法治九年级作业设计样例
- 幼儿园绘本故事:《骄傲的大公鸡》 课件
- 江西省赣州市于都县2022-2023学年九年级化学第一学期期中监测试题含解析
- 新冠核酸检测实验室PCR管八联管滤芯吸头等耗材质检和储存程序
评论
0/150
提交评论