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 =
2、 new JButton("退出系统"); ImageIcon im = 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(but
3、ton2); pcontentPane.setVisible(true); button1.addActionListener(this); button2.addActionListener(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] a
4、rgs) { WagesSystem dome = new WagesSystem(); dome.Create(); } public void actionPerformed(ActionEvent e) { if (button1.equals(e.getSource())) { DL dl = new DL(); dl.create(); frame.dispose(); } if (button2.equals(e.getSource())) { System.exit(
5、0); } } } /*登录界面*/ import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import j
6、avax.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") class DL extends JFrame implements ActionListener { NetCo
7、nn 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 JButton("财务管理员
8、登录"); 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.s
9、etBounds(130,20,150,20); frame.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(logonBu
10、tton2); logonButton3.setBounds(100,150,150,20); frame.add(logonButton3); cancelButton.setBounds(100,180,150,20); frame.add(cancelButton); logonButton1.addActionListener(this); logonButton2.addActionListener(this); logonButton3.addActionListener(this); cancelButton.addActi
11、onListener(this); sql=new NetConn();//建立数据库连接 frame.setSize(350,250); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } @SuppressWarnings("deprecation") public void actionPerformed(ActionEvent e) { t1 =
12、 username.getText(); t2 = password.getText(); //系统管理员登录 if(e.getSource()==logonButton1) { if( username.getText().equals("admin") == true && (password.getText().equals("admin") == true)) { JOptionPane.showMessageDialog(this, " 登录成功!"); xtgly a=new xtgly(
13、); 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(
14、)+"'"); String 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
15、P a=new Teacher_P(); a.creat(rs.getString(1)); frame.dispose(); } else { JOptionPane.showMessageDialog(null, "输入用户名或密码错误!"); } } else { JOptionPane.showMessageDialog(null, " 用户不存在!"); } } catch (SQLException
16、 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(
17、)) { 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));
18、frame.dispose(); } else { JOptionPane.showMessageDialog(null, "输入用户名或密码错误!"); } } else { JOptionPane.showMessageDialog(null, " 用户不存在!"); } } catch (SQLException e2) { // TODO 自动生成的 catch 块 e2.printStackTrace();
19、 } } // 退出 if (cancelButton.equals(e.getSource())) { System.exit(0); } } } /*数据库链接*/ import java.sql.*; //数据库联接类 public class NetConn { Connection con; Statement sql; public Statement connect() { try { //载入驱动程序字符串 Class.forName("com.mic
20、rosoft.sqlserver.jdbc.SQLServerDriver"); } catch(ClassNotFoundException e1) { } try { //通过JDBC URL得到Connetction对象 con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=gzxt","sa","123456"); //通过Connection对象创建Statement对象
21、 sql=con.createStatement(); } catch(SQLException e2) {} return sql; } } /*系统管理员界面*/ import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; impor
22、t java.sql.SQLException; import java.sql.Statement; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTable;
23、import javax.swing.JTextField; @SuppressWarnings("serial") class xtgly extends JFrame implements ActionListener { JFrame frame = new JFrame("教职工信息查询及密码修改"); Object a[][],b[][]; Object colname[]={"工号","姓名","密码"}; NetConn sql; Statement sqll; ResultSet rs; JTable table,table2;
24、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(null); sql=new NetConn(); sqll=
25、sql.connect(); a=new Object[30][3]; b=new Object[30][3]; try { String temp="select * from user_cw"; rs=sqll.executeQuery(temp); while(rs.next()) { a[i][0]=rs.getString(1); a[i][1]=rs.getString(2); a[i][2]=rs.getString(3); i++; } i=0; Strin
26、g temp2="select * from user_teacher"; rs=sqll.executeQuery(temp2); while(rs.next()) { b[i][0]=rs.getString(1); b[i][1]=rs.getString(2); b[i][2]=rs.getString(3); i++; } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); }
27、 table=new JTable(a,colname); table.setEnabled(false); table2=new JTable(b,colname); table2.setEnabled(false); JScrollPane JSP= new JScrollPane(table); JScrollPane JSP2= new JScrollPane(table2); tab.add(JSP,"财务管理员"); tab.add(JSP2,"教职工"); tab.setBounds(0,0,350,180); But
28、ton1.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(260,0,75,20); Button4.addActionListener(this); frame.add
29、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(ActionEvent e
30、) { //添加教职工 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
31、) { i=0; try { String temp="select * from user_cw"; rs=sqll.executeQuery(temp); while(rs.next()) { a[i][0]=rs.getString(1); a[i][1]=rs.getString(2); a[i][2]=rs.getString(3); i++; } i=0; String temp2="select * from user_teache
32、r"; rs=sqll.executeQuery(temp2); while(rs.next()) { b[i][0]=rs.getString(1); b[i][1]=rs.getString(2); b[i][2]=rs.getString(3); i++; } } catch (SQLException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } table.removeAll(
33、); 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.ResultS
34、et; 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.JPasswordField; import javax.swing.JTextField; public class Add_cw implements ActionListen
35、er { JDialog user_cw=new JDialog(); JLabel no,name,key,re_key; JTextField user_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 JLab
36、el(" 工 号:"); 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); key=new JLabel(" 密 码:"); pass=new JPas
37、swordField("",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); button1=new J
38、Button("确认"); 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); user_cw.add(u
39、ser_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(Actio
40、nEvent e) { if(e.getSource()==button1) { 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("")|| u
41、ser_name.getText().trim().equals("")) { JOptionPane.showMessageDialog(null, "输入的信息不全,请填写完整!"); } else { try { sql=new NetConn(); sqll=sql.connect(); //根据用户添加的用户名进行选择 rs=sqll.executeQuery("SELECT * FROM user_cw where no="+"'"+user_no.getTe
42、xt()+"'"); //如果已经存在同名的用户,则显示错误提示 if(rs.next()) { JOptionPane.showMessageDialog(null,"用户已经存在,添加失败!"); } //如果不存在用户名,则将用户新添加信息添加到数据库中 else { //int s1=Integer.parseInt(user_no.getText().trim()); String s1="'"+user_no.getText().trim()+"'";
43、 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 (SQLExce
44、ption e1) { e1.printStackTrace(); } } } if(e.getSource()==button2) { user_cw.dispose(); } } } /*添加教职工用户*/ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import
45、 java.sql.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_teacher implements ActionListener { JDialog user_teacher=new JDia
46、log(); 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; ResultSet rs; Add_teacher() { user_teacher.setTitle("添加教职工"); user_teacher.setLayout(null
47、); 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); key=new JLabel(" 密 码:"
48、); 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);
49、 yhk_num=new JLabel("银行卡号:"); user_yhk_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)






