企业工资管理系统Java+MySQL.docx
《企业工资管理系统Java+MySQL.docx》由会员分享,可在线阅读,更多相关《企业工资管理系统Java+MySQL.docx(31页珍藏版)》请在冰豆网上搜索。
企业工资管理系统Java+MySQL
企业工资管理系统(MySQL+Java)
本代码仅供初学者参考使用,相互学习,共同进步,让优秀成为一种习惯。
软件下载:
开发语言:
Java
开发工具:
eclipse
数据库软件:
MySQL
数据库驱动:
mysql-connector-java-5.1.6-bin
驱动下载地址:
以下是代码和界面截图,共7个类。
1.DB1欢迎界面
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
classDB1extendsJFrameimplementsActionListener{
privatestaticfinallongserialVersionUID=1L;
JFrameframe=newJFrame("欢迎进入工资管理系统");
JLabellabel=newJLabel("",JLabel.CENTER);
JButtonbutton1=newJButton("进入系统");
JButtonbutton2=newJButton("退出系统");
voidCreate(){
JPanelpcontentPane=(JPanel)frame.getContentPane();
pcontentPane.add(label);
pcontentPane.setLayout(newFlowLayout());
pcontentPane.add(button1);
pcontentPane.add(button2);
pcontentPane.setBackground(Color.gray);
pcontentPane.setVisible(true);
button1.addActionListener(this);
button2.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setBounds(500,300,300,150);
frame.setResizable(false);
frame.setVisible(true);
}
publicstaticvoidmain(String[]args){
DB1dome=newDB1();
dome.Create();
}
publicvoidactionPerformed(ActionEvente){
if(button1.equals(e.getSource())){
DLdl=newDL();
dl.create();
frame.dispose();
}
if(button2.equals(e.getSource())){//退出
System.exit(0);
}
}
}
1.DL登陆界面
importjava.awt.Color;
importjava.awt.FlowLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JPasswordField;
importjavax.swing.JTextField;
importcom.mysql.jdbc.PreparedStatement;
@SuppressWarnings("serial")
classDLextendsJFrameimplementsActionListener
{
JFrameframe=newJFrame("职工/管理员登陆");
JLabellabel1=newJLabel("用户名");
JLabellabel2=newJLabel("密码");
JButtonlogonButton1=newJButton("管理员登录");
JButtonlogonButton2=newJButton("职工登录");
JButtoncancelButton=newJButton("退出");
JTextFieldusername=newJTextField(9);
JPasswordFieldpassword=newJPasswordField(9);
staticStringt1;
staticStringt2;
voidcreate()
{
JPanelp=(JPanel)frame.getContentPane();
@SuppressWarnings("unused")
JPanelp1=newJPanel();
p.setLayout(newFlowLayout());
p.add(label1);
p.setSize(5,5);
p.setLocation(4,8);
p.add(username);
p.setSize(100,200);
p.setLocation(800,800);
p.add(label2);
p.setSize(50,20);
p.setLocation(40,80);
p.add(password);
p.setSize(100,20);
p.setLocation(80,120);
p.add(logonButton1);
p.add(logonButton2);
p.add(cancelButton);
p.setBackground(Color.gray);
p.setVisible(true);
logonButton1.addActionListener(this);
logonButton2.addActionListener(this);
cancelButton.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setBounds(500,300,500,220);
frame.setVisible(true);
}
@SuppressWarnings("deprecation")
publicvoidactionPerformed(ActionEvente)
{
t1=username.getText();
t2=password.getText();
if(e.getSource()==logonButton1)
{
if(username.getText().equals("admin")==true
&&(password.getText().equals("admin")==true))
{
JOptionPane.showMessageDialog(this,"登录成功!
");
GZGLZJMgz=newGZGLZJM();
gz.create();
frame.dispose();
}
else{
JOptionPane.showMessageDialog(null,"输入用户名或密码错误!
");
}
}
if(e.getSource()==logonButton2)
{
try{
Connectioncon;
Statementps;
ResultSetrs;
Stringsql=null;
Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con=DriverManager.getConnection(
"jdbc:
mysql:
//localhost:
3306/management","root","hellomysql");
sql="select*fromworkerwherenum='"+t1+"'andpassword='"+t2+"'";
ps=(PreparedStatement)con.prepareStatement(sql);
rs=ps.executeQuery(sql);
if(rs.next())
{
if(rs.getString("num").equals(t1)&&rs.getString("password").equals(t2))
{
YGGLZJMyg=newYGGLZJM();
yg.create();
frame.dispose();
JOptionPane.showMessageDialog(this,"登录成功!
");
this.dispose();
}
}
else{
JOptionPane.showMessageDialog(this,"输入用户名或密码错误!
");
}
}catch(Exceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
}
if(cancelButton.equals(e.getSource()))//退出
{
System.exit(0);
}
}
}
2.GZGL工资管理界面
importjava.awt.Color;
importjava.awt.FlowLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.sql.Connection;
importjava.sql.DriverManager;
impo