📄 员工个人界面.java
字号:
import java.io.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//在基本信息里面你用JLabel或Label或TextField等添加数据库的内容(哪个好用用哪个)
//选择Panel那里你要用到事件发生,很麻烦,比较多,考虑周全!
//显示查询的框子里面输出的结果要美观
//有几项数据库里面没有需要自己加列!
public class 员工个人界面 implements ActionListener{
Frame 个人界面;
//JTextArea ;
Panel 基本信息,选择;
TextArea 显示;
TextField 年;
Button 确定,取消;
JLabel 个人资料,姓名,性别,年龄,住址,联系方式,查询方式,选择日期,结果;
JTextField 输出姓名,输出性别,输出年龄,输出住址,输出联系方式;
JRadioButton box1,box2,box3,box4;
ButtonGroup box;
//CheckboxGroup choose;
Choice 月;
Label 年年,月月;
String num;
String s;
//Label lb;
员工个人界面(String s){
num=s;
init();
}
private void init(){
个人界面=new Frame("员工个人界面");
个人界面.setSize(500, 400);
个人界面.setLayout(null);
个人界面.setBackground(Color.gray);
个人界面.setLocation(300, 200);
个人界面.setResizable(false);
个人界面.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
new 主界面();
个人界面.setVisible(false);
}
});
//lb=new Label("基本信息");
//lb.setBounds(15, 20, 80, 20);
基本信息=new Panel();
基本信息.setBounds(10, 30, 220, 180);
//基本信息.setEditable(false);
基本信息.setBackground(Color.white);
基本信息.setLayout(null);
个人资料=new JLabel("个人基本信息");
个人资料.setBounds(70, 5, 80, 20);
姓名=new JLabel("姓名:");
姓名.setBounds(10, 25, 40, 20);
输出姓名=new JTextField(40);
输出姓名.setBounds(80, 25, 60, 20);
输出姓名.setEditable(false);
性别=new JLabel("性别:");
性别.setBounds(10, 50, 40, 20);
输出性别=new JTextField(40);
输出性别.setBounds(80, 50, 60, 20);
输出性别.setEditable(false);
年龄=new JLabel("年龄:");
年龄.setBounds(10, 75, 40, 20);
输出年龄=new JTextField(40);
输出年龄.setBounds(80, 75, 60, 20);
输出年龄.setEditable(false);
住址=new JLabel("住址:");
住址.setBounds(10, 100, 40, 20);
输出住址=new JTextField(40);
输出住址.setBounds(80, 100, 60, 20);
输出住址.setEditable(false);
联系方式=new JLabel("联系方式:");
联系方式.setBounds(10, 125, 80, 20);
输出联系方式=new JTextField(40);
输出联系方式.setBounds(80,125, 60, 20);
输出联系方式.setEditable(false);
基本信息.add(个人资料);
基本信息.add(姓名);
基本信息.add(性别);
基本信息.add(年龄);
基本信息.add(住址);
基本信息.add(联系方式);
基本信息.add(输出姓名);
基本信息.add(输出性别);
基本信息.add(输出年龄);
基本信息.add(输出住址);
基本信息.add(输出联系方式);
基本信息.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e){
try{
person();
}catch(SQLException ee){
ee.printStackTrace();
}
}
});
查询方式=new JLabel("查询选择:");
查询方式.setBounds(130, 0, 80, 20);
选择日期=new JLabel("日期:");
选择日期.setBounds(5, 0, 80, 20);
年=new TextField(4);
年.setBounds(10, 30, 50, 20);
年年=new Label("年");
年年.setBounds(70, 30, 20, 20);
月月=new Label("月");
月月.setBounds(70, 80, 20, 20);
月=new Choice();
月.setBounds(10, 80, 50, 20);
月.add("1");
月.add("2");
月.add("3");
月.add("4");
月.add("5");
月.add("6");
月.add("7");
月.add("8");
月.add("9");
月.add("10");
月.add("11");
月.add("12");
确定=new Button("确定");
确定.setBounds(60, 140, 40, 20);
确定.addActionListener(this);
取消=new Button("取消");
取消.setBounds(150, 140, 40, 20);
取消.addActionListener(this);
box=new ButtonGroup();
box1=new JRadioButton("工资",false);
box1.addActionListener(this);
box1.setBounds(145, 25,60,20);
box2=new JRadioButton("考勤",false);
box2.setBounds(145, 45,60,20);
box2.addActionListener(this);
box3=new JRadioButton("奖金",false);
box3.setBounds(145, 65,60,20);
box3.addActionListener(this);
box4=new JRadioButton("奖惩记录",false);
box4.setBounds(145, 85,100,20);
box4.addActionListener(this);
box.add(box1);
box.add(box2);
box.add(box3);
box.add(box4);
选择=new Panel();
选择.setBounds(240, 30, 250, 180);
选择.setLayout(null);
选择.setBackground(Color.white);
选择.add(确定);
选择.add(取消);
选择.add(选择日期);
选择.add(月);
选择.add(年);
选择.add(年年);
选择.add(月月);
选择.add(查询方式);
选择.add(box1);
选择.add(box2);
选择.add(box3);
选择.add(box4);
结果=new JLabel("查询结果");
结果.setBounds(10, 220, 80, 20);
显示=new TextArea();
显示.setBounds(10, 240, 480, 150);
显示.setEditable(false);
//显示.setBackground(Color.black);
个人界面.add(基本信息);
个人界面.add(选择);
个人界面.add(结果);
个人界面.add(显示);
//个人界面.add(lb);
个人界面.setVisible(true);
}
public void person()throws SQLException{
String number,name,sex,address,telphone;
String temp;
float age;
try{
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
}
catch(ClassNotFoundException e) { }
Connection con=DriverManager.getConnection("jdbc:odbc:wgzl");
Statement sql=con.createStatement(); //创建Statement对象
String sqly="select 姓名 ,性别 ,年龄,住址,联系方式 from xinxi where 员工编号= '"+num+"'";
ResultSet rs=sql.executeQuery(sqly);
while(rs.next()){
name=rs.getString(1);
sex=rs.getString(2);
age=rs.getFloat(3);
temp=Float.toString(age);
address=rs.getString(4);
telphone=rs.getString(5);
输出姓名.setText(name);
输出性别.setText(sex);
输出年龄.setText(temp);
输出住址.setText(address);
输出联系方式.setText(telphone);
}
}
public void listone(String s)throws SQLException{
显示.setText("");
String yue;
String year;
try{
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
}
catch(ClassNotFoundException e) { }
Connection con=DriverManager.getConnection("jdbc:odbc:wgzl");
Statement sql=con.createStatement(); //创建Statement对象
yue=月.getSelectedItem().trim();
year=年.getText().trim();
String sqly="select "+s+" from 工资表 where 年份='"+year+"' and 月份='"+yue+"' and 员工编号= '"+num+"'";
ResultSet rs=sql.executeQuery(sqly);
if(rs.next()){
显示.append(s);
显示.append(":");
显示.append(rs.getString(1));
} else {
String message="找不到您要查询的信息";
JOptionPane.showMessageDialog(个人界面, message);
}
}
public void actionPerformed(ActionEvent ee) {
String rbt=ee.getActionCommand();
if(rbt=="工资"){
s="固定工资";
}else if(rbt=="考勤"){
s="考勤";
}else if(rbt=="奖金"){
s="奖金";
}else if(rbt=="奖惩记录"){
s="奖惩记录";
}else if(ee.getSource()==确定){
try{
listone(s);
}catch(SQLException e)
{
e.printStackTrace();
}
}else if(ee.getSource()==取消){
年.setText("");
}
}
public static void main(String args[]){
new 员工个人界面("001");
}
}
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -