1、0A李萍 , 计算机系统分 向其中插入数据。讲师 insert valuesTeacherInfo0B李明C语言 语言 教授 ClassRoomInfo8:0010:12:managerjack20120521)2.创建登录界面package dev.chall.otherinterface;import java.awt.Cursor;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.even
2、t.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.SQLException;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPan
3、el;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Login extends JDialog implements ActionListenerpublic static String loginName;public Login(Frame owner, String title, boolean modal) super(owner, title, modal);init();private void init()name=new JLabel(登录名:”);nameV=new J
4、TextField(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.setActionCommand(loginlogin.addActionListener(this);quit=new JB
5、utton( 退出 quit.setActionCommand(quitquit.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, 1);this.setLocation(550, 230);this.setSize(200,200);this.setVisible(true);Overridepublic void
6、 actionPerformed(ActionEvent arg0) if(arg0.getActionCommand()=String name=nameV .getText();String psw=pswV .getText();if(name.length()=0|psw.length()=0)prompt.setText( 提示:用户名或密码为空!return;if(checkCount(name,psw)this.dispose();else用户名或密码错误!else if(arg0.getActionCommand()=System.exit(0);private boolean
7、 checkCount(String name,String psw)Connection connection=null;PreparedStatement ps=null;ResultSet rs=null;try /加载驱动Class.forName(sun.jdbc.odbc.JdbcOdbcDriversa,/得到连接 connection=DriverManager.getConnection(jdbc:odbc:classManagersongchao/创建访问数据库接口 ps=connection.prepareStatement(select * from managerrs
8、=ps.executeQuery();while(rs.next()String namet=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.printStackTrace();finallyrs.close();ps.close();connect
9、ion.close(); catch (SQLException e) return false;protected void processWindowEvent(WindowEvent arg0) super.processWindowEvent(arg0);if(arg0.getID()=WindowEvent.WINDOW_CLOSING)3.实现主界面,实现各按钮的作用package dev.chall.main;import java.awt.BorderLayout;import java.awt.Font;import java.awt.event.ItemEvent;impo
10、rt java.awt.event.ItemListener;import java.util.Iterator;import java.util.Vector;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.JTable;import dev.chall.otherinterface.Delete;import dev.chall.otherinterface.Insert
11、;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 implements ActionListener/登录界面Login login;/主控制界面/topBar/rightBarprivate JButton searchB,alert,ins
12、ert,delete;private JTextField searchT;/搜索字样/centerBarprivate JScrollPane scroll;private MyTableModel model;private String list=new String 教师信息 ,教室信息 教室使用情况 教室具体使用情况;private JLabel remind;public static void main(String args)new ControlInterface();public ControlInterface()/登录界面 login=new Login(this, ,
13、true);/登陆界面回来之后userName.setText(Login.loginName);userName.setFont(new Font(隶书,1,25);/ 字体,1 代表样式,字号userName.setLocation(this.getWidth()/2-userName.getWidth()/2,userName.getHeight()/3);topBar.add(userName,BorderLayout.CENTER);quit.setLocation(int) (this.getWidth()-quit.getWidth()*1.5),userName.getHeig
14、ht()/3);topBar.add(quit,BorderLayout.EAST);this.add(topBar,BorderLayout.NORTH);/rightBar rightBar=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(
15、list);operation.addItemListener(new ItemListener()Override public void itemStateChanged(ItemEvent arg0) searchT.setTextC请输入+ operation.getSelectedItem().toString().substring(0,2)+ 编号content.setModel(model);) ;operationP.add(operationT);operationP.add(operation);buttonP=new JPanel();buttonP.setLayout
16、(new GridLayout(3,1);alert=new JButton( 修改 alert.addActionListener(this);alert.setActionCommand(alertinsert=new JButton( 增加 insert.addActionListener(this);insert.setActionCommand(insertdelete=new JButton( 删除 delete.addActionListener(this);delete.setActionCommand(deletebuttonP.add(alert);buttonP.add(
17、insert);buttonP.add(delete);operationP.add(buttonP);rightBar.add(operationP);search=new JLabel(关键字:searchT=new JTextField(10);searchT.setText(”请输入+operation.getSelectedltem().toString().substring(0,2)+编号 searchB=new JButton(搜索searchB.addActionListener(this);searchB.setActionCommand(searchsearchP=new
18、 JPanel();searchP.setLayout(new FlowLayout();searchP.add(search);searchP.add(searchT);searchP.add(searchB);rightBar.add(searchP);remind=new JLabel();rightBar.add(remind);/centerBar model=new MyTableModel(operation.getSelectedItem().toString();content=new JTable(model);scroll=new JScrollPane(content)
19、;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()= 教室具体使用情况 new RemindDialog(this, 提示 ,true,0);new Insert(
20、this, 增加新数据 ,true,operation.getSelectedItem().toString();if(content.getSelectedRow()=-1),true,1);Vector v=(Vector)MyTableModel.rowData.get(content.getSelectedRow();new Update(this,true,operation.getSelectedItem().toString(),v);model=new MyTableModel(operation.getSelectedItem().toString();Vector v=(V
21、ector) MyTableModel.rowData.get(content.getSelectedRow();new Delete(this,true,v,operation.getSelectedItem().toString();private void search2UnionTable()Vector v=MyTableModel.select(operation.getSelectedItem().toString();Vector rowData=new Vector();Iterator iterator=v.iterator();String rNum=searchT.ge
22、tText().toString().trim();while(iterator.hasNext()Vector tem=(Vector)iterator.next();if(String)tem.get(0).equals(rNum)rowData.add(tem);if(rowData.size()=0)remind.setText( 无该教室信息 MyTableModel my=new MyTableModel(rowData,MyTableModel.columnNames);content.setModel(my);4.向主界面中加载数据package dev.chall.util;
23、import javax.swing.table.AbstractTableModel;public class MyTableModel extends AbstractTableModelpublic MyTableModel(String value) select(value);this.rowData=rowData;this.columnNames=columnNames;public static Vector select(String value)rowData=new Vector();columnNames=new Vector();String sql = null;if(value=columnNames.add( 教师编号 教师姓名 columnNames.a
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1