1、工资系统代码/*系统欢迎界面*/import java.awt.FlowLayout;import java.awt.event.*; import javax.swing.*; SuppressWarnings(serial)class WagesSystem extends JFrame implements ActionListener JFrame frame = new JFrame(欢迎进入工资管理系统); JButton button1 = new JButton(进入系统); JButton button2 = new JButton(退出系统); ImageIcon im =
2、 new ImageIcon(1.jpg); JLabel a1 = new JLabel(im); void Create() JPanel pcontentPane = (JPanel) frame.getContentPane();pcontentPane.add(a1); pcontentPane.setLayout(new FlowLayout();pcontentPane.add(button1); pcontentPane.add(button2); pcontentPane.setVisible(true); button1.addActionListener(this); b
3、utton2.addActionListener(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null);frame.setVisible(true); public static void main(String args) WagesSystem dome = new WagesSystem(); dome.Create(); public void actionPerformed(ActionEvent e) if (butto
4、n1.equals(e.getSource() DL dl = new DL(); dl.create(); frame.dispose(); if (button2.equals(e.getSource()System.exit(0); /*登录界面*/import java.awt.HeadlessException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import jav
5、a.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;import .*;import java.sql.*;SuppressWarnings(serial)cla
6、ss DL extends JFrame implements ActionListener NetConn sql;Statement sqll;ResultSet rs;JFrame frame = new JFrame(职工/管理员登陆);JLabel label1 = new JLabel(用户名);JLabel label2 = new JLabel(密 码);JButton logonButton1 = new JButton(系统管理员登录);JButton logonButton2 = new JButton(教职工登录);JButton logonButton3 = new
7、JButton(财务管理员登录);JButton cancelButton = new JButton(退出);JTextField username = new JTextField(9);JPasswordField password = new JPasswordField(9);static String t1;static String t2;void create() frame.setLayout(null);label1.setBounds(60,20,50,20);frame.add(label1);username.setBounds(130,20,150,20);fram
8、e.add(username);label2.setBounds(60,50,50,20);frame.add(label2);password.setBounds(130,50,150,20);frame.add(password);logonButton1.setBounds(100,90,150,20);frame.add(logonButton1);logonButton2.setBounds(100,120,150,20);frame.add(logonButton2);logonButton3.setBounds(100,150,150,20);frame.add(logonBut
9、ton3);cancelButton.setBounds(100,180,150,20);frame.add(cancelButton);logonButton1.addActionListener(this);logonButton2.addActionListener(this);logonButton3.addActionListener(this);cancelButton.addActionListener(this);sql=new NetConn();/建立数据库连接frame.setSize(350,250);frame.setLocationRelativeTo(null);
10、frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);SuppressWarnings(deprecation)public void actionPerformed(ActionEvent e) t1 = username.getText();t2 = password.getText();/系统管理员登录if(e.getSource()=logonButton1)if( username.getText().equals(admin) = true& (password.getText().e
11、quals(admin) = true) JOptionPane.showMessageDialog(this, 登录成功!);xtgly a=new xtgly();frame.dispose(); else JOptionPane.showMessageDialog(null, 输入用户名或密码错误!);/教职工登陆if(e.getSource()=logonButton2)sqll=sql.connect(); try rs=sqll.executeQuery(SELECT * FROM user_teacher where name=+username.getText()+);Stri
12、ng sname,spass;if(rs.next()sname=rs.getString(2); spass=rs.getString(3);if(password.getText().trim().equals(spass)&(username.getText().trim().equals(sname) JOptionPane.showMessageDialog(this, 登录成功!);Teacher_P a=new Teacher_P();a.creat(rs.getString(1);frame.dispose(); elseJOptionPane.showMessageDialo
13、g(null, 输入用户名或密码错误!);elseJOptionPane.showMessageDialog(null, 用户不存在!); catch (SQLException e2) / TODO 自动生成的 catch 块e2.printStackTrace();/财务登陆if (e.getSource()=logonButton3)sqll=sql.connect(); try rs=sqll.executeQuery(SELECT * FROM user_cw where name=+username.getText()+);String sname,spass;if(rs.next
14、()sname=rs.getString(2); spass=rs.getString(3);if(password.getText().trim().equals(spass)&(username.getText().trim().equals(sname) JOptionPane.showMessageDialog(this, 登录成功!);CW a=new CW();a.create(rs.getString(1);frame.dispose(); elseJOptionPane.showMessageDialog(null, 输入用户名或密码错误!);elseJOptionPane.s
15、howMessageDialog(null, 用户不存在!); catch (SQLException e2) / TODO 自动生成的 catch 块e2.printStackTrace();/ 退出if (cancelButton.equals(e.getSource() System.exit(0);/*数据库链接*/import java.sql.*;/数据库联接类public class NetConn Connection con;Statement sql;public Statement connect()try /载入驱动程序字符串 Class.forName(.micros
16、oft.sqlserver.jdbc.SQLServerDriver); catch(ClassNotFoundException e1) try /通过JDBC URL得到Connetction对象 con=DriverManager.getConnection(jdbc:sqlserver:/localhost:1433;DatabaseName=gzxt,sa,123456); /通过Connection对象创建Statement对象 sql=con.createStatement(); catch(SQLException e2) return sql;/*系统管理员界面*/impor
17、t java.awt.BorderLayout;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing
18、.JLabel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JTabbedPane;import javax.swing.JTable;import javax.swing.JTextField;SuppressWarnings(serial)class xtgly extends JFrame implements ActionListenerJFrame frame = new JFrame(教职工信息查询及密码修改);Object a,b; Object colna
19、me=工号,姓名,密码;NetConn sql;Statement sqll;ResultSet rs;JTable table,table2;JButton Button1 = new JButton(添加教职工);JButton Button2 = new JButton(添加财务管理员);JButton Button3 = new JButton(修改密码);JButton Button4 = new JButton(刷新);JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP); int i=0;xtgly()frame.setLayout
20、(null);sql=new NetConn();sqll=sql.connect();a=new Object303;b=new Object303;try String temp=select * from user_cw;rs=sqll.executeQuery(temp);while(rs.next()ai0=rs.getString(1);ai1=rs.getString(2);ai2=rs.getString(3);i+;i=0;String temp2=select * from user_teacher;rs=sqll.executeQuery(temp2);while(rs.
21、next()bi0=rs.getString(1);bi1=rs.getString(2);bi2=rs.getString(3);i+; catch (SQLException e) / TODO 自动生成的 catch 块e.printStackTrace();table=new JTable(a,colname);table.setEnabled(false);table2=new JTable(b,colname);table2.setEnabled(false);JScrollPane JSP= new JScrollPane(table);JScrollPane JSP2= new
22、 JScrollPane(table2);tab.add(JSP,财务管理员);tab.add(JSP2,教职工);tab.setBounds(0,0,350,180);Button1.setBounds(1,185,110,20);Button1.addActionListener(this);Button2.setBounds(115,185,125,20);Button2.addActionListener(this);Button3.setBounds(245,185,89,20);Button3.addActionListener(this);Button4.setBounds(26
23、0,0,75,20);Button4.addActionListener(this);frame.add(Button1);frame.add(Button2);frame.add(Button3);frame.add(Button4);frame.add(tab);frame.setSize(350,250);frame.setLocationRelativeTo(null);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public void actionPerformed(Actio
24、nEvent e)/添加教职工if(e.getSource()=Button1)Add_teacher add1=new Add_teacher();/添加财务管理员if(e.getSource()=Button2)Add_cw add2=new Add_cw();/修改密码if(e.getSource()=Button3)Change_mima change=new Change_mima();if(e.getSource()=Button4)i=0;try String temp=select * from user_cw;rs=sqll.executeQuery(temp);while(
25、rs.next()ai0=rs.getString(1);ai1=rs.getString(2);ai2=rs.getString(3);i+;i=0;String temp2=select * from user_teacher;rs=sqll.executeQuery(temp2);while(rs.next()bi0=rs.getString(1);bi1=rs.getString(2);bi2=rs.getString(3);i+; catch (SQLException e1) / TODO 自动生成的 catch 块e1.printStackTrace();table.remove
26、All();table2.removeAll();table=new JTable(a,colname);table.setEnabled(false);table2=new JTable(b,colname);table2.setEnabled(false);tab.updateUI();/*添加财务管理人员*/import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.
27、Statement;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Add_cw implements ActionListenerJDialog user_cw=new JDialog();JLabel no,name,key,re_key;JTextField use
28、r_no,user_name;JPasswordField pass,aenter;JButton button1,button2;NetConn sql;Statement sqll;ResultSet rs;Add_cw()user_cw.setTitle(添加财务管理员);user_cw.setLayout(null);no=new JLabel( 工 号:);user_no=new JTextField(,10);user_no.setBounds(115,5,120,20);no.setBounds(20,5,80,20);name=new JLabel( 姓 名:);user_na
29、me=new JTextField(,10);user_name.setBounds(115,30,120,20);name.setBounds(20,30,80,20);key=new JLabel( 密 码:);pass=new JPasswordField(,10);pass.setEchoChar(*);pass.setBounds(115,55,120,20);key.setBounds(20,55,80,20);re_key=new JLabel(确认密码:);aenter=new JPasswordField(,10);aenter.setEchoChar(*);aenter.s
30、etBounds(115,80,120,20);re_key.setBounds(20,80,80,20);button1=new JButton(确认);button1.setBounds(50,110,80,20);button1.addActionListener(this);button2=new JButton(取消);button2.setBounds(170,110,80,20);button2.addActionListener(this);user_cw.add(no);user_cw.add(name);user_cw.add(key);user_cw.add(re_key
31、);user_cw.add(user_no);user_cw.add(user_name);user_cw.add(pass);user_cw.add(aenter);user_cw.add(button1);user_cw.add(button2);user_cw.setSize(300,180);user_cw.setModal(true);user_cw.setLocationRelativeTo(null);user_cw.setVisible(true);public void actionPerformed(ActionEvent e)if(e.getSource()=button
32、1)String s=aenter.getText().trim();if(!(pass.getText().trim().equals(s)JOptionPane.showMessageDialog(null, 两次输入的密码不一致!);else if(pass.getText().trim().equals()|user_no.getText().trim().equals()|user_name.getText().trim().equals()JOptionPane.showMessageDialog(null, 输入的信息不全,请填写完整!);elsetry sql=new NetC
33、onn(); sqll=sql.connect();/根据用户添加的用户名进行选择rs=sqll.executeQuery(SELECT * FROM user_cw where no=+user_no.getText()+);/如果已经存在同名的用户,则显示错误提示if(rs.next()JOptionPane.showMessageDialog(null,用户已经存在,添加失败!);/如果不存在用户名,则将用户新添加信息添加到数据库中else/int s1=Integer.parseInt(user_no.getText().trim();String s1=+user_no.getTex
34、t().trim()+;String s2=+user_name.getText().trim()+;String s3=+pass.getText().trim()+;String temp=INSERT INTO user_cw VALUES (+s1+,+s2+,+s3+);sqll.executeUpdate(temp);JOptionPane.showMessageDialog(null,用户添加成功!); catch (SQLException e1) e1.printStackTrace();if(e.getSource()=button2)user_cw.dispose();/
35、*添加教职工用户*/import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswor
36、dField;import javax.swing.JTextField;public class Add_teacher implements ActionListenerJDialog user_teacher=new JDialog();JLabel no,name,key,re_key,yhk_num,zhiwu;JTextField user_no,user_name,user_yhk_num,user_zhiwu;JPasswordField pass,aenter;JButton button1,button2;NetConn sql;Statement sqll;ResultS
37、et rs;Add_teacher()user_teacher.setTitle(添加教职工);user_teacher.setLayout(null);no=new JLabel( 工 号:);user_no=new JTextField(,10);user_no.setBounds(115,5,120,20);no.setBounds(20,5,80,20);name=new JLabel( 姓 名:);user_name=new JTextField(,10);user_name.setBounds(115,30,120,20);name.setBounds(20,30,80,20);k
38、ey=new JLabel( 密 码:);pass=new JPasswordField(,10);pass.setEchoChar(*);pass.setBounds(115,55,120,20);key.setBounds(20,55,80,20);re_key=new JLabel(确认密码:);aenter=new JPasswordField(,10);aenter.setEchoChar(*);aenter.setBounds(115,80,120,20);re_key.setBounds(20,80,80,20);yhk_num=new JLabel(银行卡号:);user_yh
39、k_num=new JTextField(,10);user_yhk_num.setBounds(115,105,120,20);yhk_num.setBounds(20,105,80,20);zhiwu=new JLabel( 职 务:);user_zhiwu=new JTextField(,10);user_zhiwu.setBounds(115,130,120,20);zhiwu.setBounds(20,130,80,20);button1=new JButton(确认);button1.setBounds(50,160,80,20);button1.addActionListener(this);button2=new JButton(取消);button2.setBounds(170,160,80,20);button2.addActionListener(this);user_teacher.add(no);user_teacher.add(name);user_teacher.add(key);
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100