📄 ex1_1.java
字号:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class ex1_1 implements ActionListener{
JFrame f=null;
public ex1_1() {
f=new JFrame("员工信息");
Container p =f.getContentPane();
JPanel bp=new JPanel();
JButton b1=new JButton("员工登记");
b1.addActionListener(this);
JButton b2=new JButton("工资管理");
b2.addActionListener(this);
JButton b3=new JButton("流动管理");
b3.addActionListener(this);
bp.add(b1);
bp.add(b2);
bp.add(b3);
p.add(bp);
f.pack();
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
} );
}
public void actionPerformed(ActionEvent e){
String cmd=e.getActionCommand();
if(cmd.equals("员工登记")){
new regist(f);
}
else if(cmd.equals("工资管理")){
new gongzi(f);
}
else
{new liudong(f);
}
}
public static void main(String[] args)
{
new ex1_1();
}
}
class regist implements ActionListener
{JDialog dialog;
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextField tf4=new JTextField();
regist(JFrame f)
{dialog=new JDialog(f,"员工登记",true);
Container dp=dialog.getContentPane();
dp.setLayout(new GridLayout(5,4));
dp.add(new JLabel("编号:",SwingConstants.CENTER));
dp.add(tf2);
dp.add(new JLabel("姓名:",SwingConstants.CENTER));
dp.add(tf1);
dp.add(new JLabel("部门:",SwingConstants.CENTER));
dp.add(tf3);
dp.add(new JLabel("工资:",SwingConstants.CENTER));
dp.add(tf4);
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");
dp.add(b1);
dp.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
dialog.setBounds(200,150,400,130);
dialog.show();
}
public void actionPerformed(ActionEvent e)
{String cmd=e.getActionCommand();
if(cmd.equals("确定")){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:yuangong");
Statement stmt=con.createStatement();
String sno=tf1.getText();
String sno1=tf2.getText();
String sno2=tf3.getText();
String sno3=tf4.getText();
String str1="insert into 员工表 values('"+sno+"','"+sno1+"','"+sno2+"','"+sno3+"')";
stmt.executeUpdate(str1);
stmt.close();
con.close();
}
catch(Exception ex){}
}
else if(cmd.equals("取消")){
dialog.dispose();}
}
}
class gongzi implements ActionListener
{JDialog dialog;
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextField tf4=new JTextField();
gongzi(JFrame f)
{dialog=new JDialog(f,"工资表",true);
Container dp=dialog.getContentPane();
dp.setLayout(new GridLayout(5,4));
dp.add(new JLabel("编号:",SwingConstants.CENTER));
dp.add(tf2);
dp.add(new JLabel("应得工资:",SwingConstants.CENTER));
dp.add(tf1);
dp.add(new JLabel("扣除:",SwingConstants.CENTER));
dp.add(tf3);
dp.add(new JLabel("实得:",SwingConstants.CENTER));
dp.add(tf4);
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");
dp.add(b1);
dp.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
dialog.setBounds(200,150,400,130);
dialog.show();
}
public void actionPerformed(ActionEvent e)
{String cmd=e.getActionCommand();
if(cmd.equals("确定")){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:yuangong");
Statement stmt=con.createStatement();
String sno=tf1.getText();
String sno1=tf2.getText();
String sno2=tf3.getText();
String sno3=tf4.getText();
String str1="insert into 工资表 values('"+sno+"','"+sno1+"','"+sno2+"','"+sno3+"')";
stmt.executeUpdate(str1);
stmt.close();
con.close();
}
catch(Exception ex){}
}
else if(cmd.equals("取消")){
dialog.dispose();}
}
}
class liudong implements ActionListener
{JDialog dialog;
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
liudong(JFrame f)
{dialog=new JDialog(f,"人员流动",true);
Container dp=dialog.getContentPane();
dp.setLayout(new GridLayout(4,4));
dp.add(new JLabel("编号:",SwingConstants.CENTER));
dp.add(tf2);
dp.add(new JLabel("现在部门:",SwingConstants.CENTER));
dp.add(tf1);
dp.add(new JLabel("转到部门",SwingConstants.CENTER));
dp.add(tf3);
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");
dp.add(b1);
dp.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
dialog.setBounds(200,150,400,130);
dialog.show();
}
public void actionPerformed(ActionEvent e)
{String cmd=e.getActionCommand();
if(cmd.equals("确定")){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:yuangong");
Statement stmt=con.createStatement();
String sno=tf1.getText();
String sno1=tf2.getText();
String sno2=tf3.getText();
String str1="insert into 流动表 values('"+sno+"','"+sno1+"','"+sno2+"')";
stmt.executeUpdate(str1);
stmt.close();
con.close();
}
catch(Exception ex){}
}
else if(cmd.equals("取消")){
dialog.dispose();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -