?? manager.java
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Hashtable;//數(shù)據(jù)類型類
//主窗口
public class Manager extends Frame implements ActionListener
{ MenuBar bar;
Menu fileMenu,fileMenu1,fileMenu2,fileMenu3,fileMenu0,m;
MenuItem 登陸,錄入,修改,查詢,刪除,mi;
Container Con=null;
CardLayout card=null;
JLabel label=null;
TextField 工號,姓名;
TextField 工齡;
TextField 年齡,性別;
Button 增加用戶,取消,刪除按鈕;
Update dd; //聲明一個(gè)修改窗口的對象
Useradd aa;
Userfind bb;
Delete cc;
Connection con=null;Statement Stmt=null;
Manager(){
super("歡迎使用WWW員工信息管理系統(tǒng)");
setBackground(Color.blue);
int 查詢記錄=0;
Connection Con=null;Statement Stmt=null;
dd=new Update();
aa=new Useradd();
bb=new Userfind();
cc=new Delete();
//setBounds(150,150,300,300);
setVisible(true);setLayout(new GridLayout(6,3));
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
Stmt=con.createStatement();
}
catch(SQLException ee) {}
工號=new TextField(16);
姓名=new TextField(16);
性別=new TextField(16);
工齡=new TextField(16);
年齡=new TextField(16);
增加用戶=new Button("增加");
取消=new Button("取消");
刪除按鈕=new Button("刪除");
Panel p1=new Panel(),p2=new Panel(),p3=new Panel();
p1.add(new Label("工號:"));
p1.add(工號);
p1.add(new Label("姓名:"));
p1.add(姓名);
p1.add(new Label("性別:"));
p1.add(性別);
p2.add(new Label("工齡:"));
p2.add(工齡);
p2.add(new Label("年齡:"));
p2.add(年齡);
p3.add(增加用戶);
p3.add(取消);
p3.add(刪除按鈕);
setLayout(new GridLayout(12,10));
add(p1);add(p2);add(p3);
登陸=new MenuItem("注冊賬號");
錄入=new MenuItem("錄入員工基本信息");
修改=new MenuItem("修改員工基本信息");
查詢=new MenuItem("查詢員工基本信息");
刪除=new MenuItem("刪除員工基本信息");
mi=new MenuItem("責(zé)任表duty");
bar=new MenuBar();
fileMenu0=new Menu("注冊用戶");
fileMenu=new Menu("增加員工信息");
fileMenu1=new Menu("修改信息");
fileMenu2=new Menu("查詢員工信息");
fileMenu3=new Menu("刪除員工信息");
m=new Menu("鏈接");
fileMenu0.add(登陸);
fileMenu.add(錄入);
fileMenu1.add(修改);
fileMenu2.add(查詢);
fileMenu3.add(刪除);
m.add(mi);
bar.add(fileMenu0);
bar.add(fileMenu);
bar.add(fileMenu1);
bar.add(fileMenu2);
bar.add(fileMenu3);
bar.add(m);
setMenuBar(bar);
//label=new JLabel("請先登陸系統(tǒng)后使用該系統(tǒng)!",JLabel.SOUTH);
label=new JLabel("歡迎使用WWW公司員工基信息管理系統(tǒng)",JLabel.CENTER);
label.setFont(new Font("TimesRoman",Font.BOLD,24));
label.setForeground(Color.red);
add (label);
//add (label1);
//工人工號=s1;
增加用戶.addActionListener(this);
取消.addActionListener(this);
刪除按鈕.addActionListener(this);
//設(shè)置按鈕的不可用
//取消.setEnabled(false);
//增加按鈕.setEnabled(false);
//刪除按鈕.setEnabled(false);
登陸.addActionListener(this);
錄入.addActionListener(this);
修改.addActionListener(this);
查詢.addActionListener(this);
刪除.addActionListener(this);
mi.addActionListener(this);
setVisible(false);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
//setVisible(true);
setBounds(100,50,800,400);
validate();
}
//按鈕事件
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==登陸)
{ setVisible(false);
aa.setVisible(true);
}
else if(e.getSource()==錄入)
{
try{ 錄入();}
catch(SQLException ee) {}
String warning="確定要增加員工信息嗎?";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
else if(e.getSource()==查詢)
{
setVisible(false);
bb.setVisible(true);
}
else if(e.getSource()==刪除)
{
setVisible(false);
cc.setVisible(true);
}
else if(e.getSource()==修改)
{ setVisible(false);
dd.setVisible(true);
}
else if(e.getSource()==mi)
{ setVisible(false);
Duty d = new Duty();
d.setVisible(true);
}
else if(e.getSource()==取消)
{ 工號.setText(null);
姓名.setText(null);
性別.setText(null);
工齡.setText(null);
年齡.setText(null);
}
}
public void 錄入() throws SQLException
{
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
Stmt=con.createStatement();
}
catch(SQLException ee) {}
String s1="'"+工號.getText().trim()+"'";
String s2="'"+姓名.getText().trim()+"'";
String s4="'"+工齡.getText().trim()+"'";
String s5="'"+年齡.getText().trim()+"'";
String s6="'"+性別.getText().trim()+"'";
String temp="INSERT INTO info VALUES ("+s1+","+s2+","+s4+","+s5+","+s6+")";
con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
Stmt.executeUpdate(temp);
con.close();
}
}
//修改員工信息窗口
class Update extends Frame implements ActionListener
{ TextField 工號,姓名;
TextField 工齡;
TextField 年齡,性別;
Button 確定修改,取消修改;
Connection con =null;Statement stmt=null;
Update( )
{ super("歡迎使用WWW員工管理系統(tǒng)");
//setBackground(Color.blue);
setBounds(10,10,1000,300);
setVisible(false);
validate();
工號=new TextField(16);
姓名=new TextField(16);
工齡=new TextField(16);
年齡=new TextField(16);
性別=new TextField(16);
確定修改=new Button("確定修改");
取消修改=new Button("取消修改");
確定修改=new Button("確定修改");
取消修改=new Button("取消修改");
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
// Panel p3=new Panel();
p1.add(new Label("工號:"));
p1.add(工號);
p1.add(new Label("姓名:"));
p1.add(姓名);
p2.add(new Label("工齡:"));
p2.add(工齡);
p2.add(new Label("年齡:"));
p2.add(年齡);
p2.add(new Label("性別:"));
p2.add(性別);
//p2.add(性別);p2.add(性別);
add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.CENTER);
p2.add(確定修改);p2.add(取消修改);
確定修改.addActionListener(this);
取消修改.addActionListener(this);
setVisible(false);
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){ }
try{
con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
stmt=con.createStatement();
}
catch(SQLException ee) { }
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==確定修改)
{try{ xg();}
catch(SQLException ee){}
String warning="確定要修改員工信息嗎?";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}
else if(e.getSource()==取消修改)
{工號.setText(null);
姓名.setText(null);
工齡.setText(null);
年齡.setText(null);
性別.setText(null);
}
}
public void xg() throws SQLException
{ String s1="'"+工號.getText().trim()+"'";
String s4="'"+工齡.getText().trim()+"'";
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -