版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、华侨大学厦门工学院面向对象程序设计实践课程实验报告(分组实验)实验名称 员工基本信息管理系统系 部 计算机科学与工程系班 级软件3班小组名称 第三组指导老师文欣计算机科学与工程系2014年06月12日一、 实验名称员工基本信息管理系统二、实验目的及任务要求目的:对员工的信息进行有效的管理和储存任务要求:对员工的信息进行增加,删除,查找,修改等功能三、实验环境eclipse.exe四、实验内容/ 注册用户import javax.swing.*;import java.awt.*;import java.awt.Event.*;import java.awt.event.ActionEvent;
2、import java.awt.event.ActionListener;import java.sql.*;public class UserRegister extends JFrame implements ActionListener JLabel lblUserName;JLabel lblUserPwd;JTextField txtUserName;JPasswordField txtUserPwd;JButton btnRegister;JButton btnCancel;public UserRegister() super(" 用户注册 ");lblUse
3、rName = new JLabel(" 用户名 ");lblUserName.setBounds(40, 40, 70, 50);txtUserName = new JTextField(10);txtUserName.setBounds(120, 50, 100, 24);lblUserPwd = new JLabel(" 密码 ");lblUserPwd.setBounds(40, 70, 70, 50);txtUserPwd = new JPasswordField(10);txtUserPwd.setEchoChar('*');
4、txtUserPwd.setBounds(120, 85, 100, 24);btnRegister = new JButton(" 注册 ");btnRegister.setBounds(55, 135, 60, 30);btnCancel = new JButton(" 取消 ");btnCancel.setBounds(140, 135, 60, 30);Container cc = this.getContentPane();cc.setLayout(null);cc.add(lblUserName);cc.add(txtUserName);cc
5、.add(lblUserPwd);cc.add(txtUserPwd);cc.add(btnRegister);cc.add(btnCancel);btnRegister.addActionListener(this);btnCancel.addActionListener(this);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setLocation(300, 200);this.setSize(270, 220);this.setResizable(false);this.setVisible(true);public void ac
6、tionPerformed(ActionEvent e) if (e.getSource() = btnRegister) DataBaseManager db = new DataBaseManager();String username = txtUserName.getText().trim();char pwd = txtUserPwd.getPassword();String password = new String(pwd);password = password.trim();if (username.equals("") | password.equals
7、("") System.out.println(username.trim();JOptionPane.showMessageDialog(null, " 用户名或密码不能为空");return;String sql = "select * from user where username=" + "'" + username+ ;ResultSet rs = db.getResult(sql);try if (rs.next() JOptionPane.showMessageDialog(null, &q
8、uot; 该 用 户 名 已 存 在 !", Message",JOptionPane.DEFAULT_OPTION); else sql = "insert into user values(" + "'" + username + "'"+ ",'" + password + "')"db.updateSql(sql);System.out.println(sql);JOptionPane.showMessageDialog(null, &
9、quot; 注 册 成 功 !",Message",JOptionPane.DEFAULT_OPTION);catch (Exception ee) System.out.println(ee.getMessage(); finally db.closeConnection();else if (e.getSource() = btnCancel) this.dispose();public static void main(String args) new UserRegister();/用户登录import java.awt.Color;import java.awt.
10、Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.HeadlessException;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.DriverManager;import java.sql.Statement;import java.sql.Connection;import java.sql.ResultSet;impo
11、rt java.sql.SQLException;import javax.swing.AbstractButton;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;class Login extends JFrame implements Act
12、ionListener /JLabel j1 = null;JTextField text = null;/JLabel j2 = null;JLabel j3 = null;JLabel j4 = null;JPasswordField pass = null;JTextField text1 =null;JButton b1 = null;JButton b2 = null;Font fnt = new Font(" 方正舒体 ", Font.BOLD, 20);验证码 .jpg");登录界面 .jpg");public Login(String t
13、itle) throws HeadlessException super(title);/ TODO Auto-generated constructor stub/j1 = new JLabel(" 用户名 ");/j1.setFont(fnt);/j1.setForeground(Color.white);text = new JTextField(10);text.setFont(fnt);text.setForeground(Color.black);text.setOpaque(false);text.setBorder(null);text1=new JText
14、Field(10);text1.setFont(fnt);text1.setForeground(Color.black);text1.setOpaque(false);text1.setBorder(null);/j2 = new JLabel(" 密码 ");/j2.setFont(fnt);/j2.setForeground(Color.white);j3=new JLabel(" ");j3.setFont(fnt);j3.setForeground(Color.white);pass = new JPasswordField(10);pass.
15、setEchoChar('*');pass.setFont(new Font("",Font.ITALIC,15);pass.setForeground(Color.black);pass.setOpaque(false);pass.setBorder(null);b1 = new JButton(" ");b1.setFont(fnt);b1.setForeground(Color.white);b1.setContentAreaFilled(false);b1.setBorder(null);b2 = new JButton(&quo
16、t; ");b2.setFont(fnt);b2.setForeground(Color.white);b2.setContentAreaFilled(false);b2.setBorder(null);int xcenter =155;int ycenter = 50;setLocation(xcenter, ycenter);jpanel.setLayout(null);setSize(1050,680);p.setBounds(750,371,82,28);/j1.setBounds(40, 40, 70, 30);text.setBounds(538, 283, 177, 3
17、0);/j2.setBounds(40, 100, 70, 50);pass.setBounds(538, 326, 177, 30);text1.setBounds(538,370,177,30);b1.setBounds(531, 444, 76, 23);b2.setBounds(646, 444, 76, 23);/jpanel.add(j1);jpanel.add(text);/jpanel.add(j2);jpanel.add(pass);jpanel.add(text1);jpanel.add(b1);jpanel.add(b2);jpanel.add(p);this.getCo
18、ntentPane().add(jpanel);b1.addActionListener(this);b2.addActionListener(this);this.setResizable(false);this.setVisible(true);public void actionPerformed(ActionEvent e) DataBaseManager db = new DataBaseManager();String sql = "select * from user"ResultSet rs = db.getResult(sql);boolean flag
19、= false;if (e.getSource() = b1) try while (rs.next() boolean flag1 = text.getText().trim().equals(rs.getString(1);boolean flag2 = pass.getText().trim().equals( rs.getString(2);if (flag1 && flag2) if(text1.getText().trim().equals("xahv") flag = true;JOptionPane.showMessageDialog(thi
20、s, " 成功登陆 ");dispose();new StaffMain(" 员工信息管理系统");/ TODO Auto-generated method stubelseflag = true;JOptionPane.showMessageDialog(this, " 验证码错误");/dispose();if (flag = false) JOptionPane.showMessageDialog(this, " 用户名或密码错误" );text.setText("");pass.setT
21、ext("");catch (SQLException e1) / TODO Auto-generated catch block e1.printStackTrace();if (e.getSource() = b2) text.setText("");text1.setText(""); pass.setText("");public class TestLogin /* param args*/public static void main(String args) / TODO Auto-generated
22、 method stub new Login(" 登陆 ");/主界面import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import java.awt.GridLayout;import java.awt.HeadlessExcept
23、ion;import java.awt.Image;import java.awt.Toolkit;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.a
24、wt.event.InputEvent;import javax.swing.*;public class StaffMain extends JFrame implements ActionListener private Font fnt = new Font(" 方正舒体 ", Font.BOLD, 25);private JButton j1 = new JButton("addprivate JButton j2 = new JButton("edit");修改员工信息”);private JButton j3 = new JButt
25、on("del");private JButton j4 = new JButton("query");private JButton j5 = new JButton("all");private JButton j6 = new JButton("exit关于系统");private JLabel label = new JLabel(" 欢迎进入员工管理系统");private JPanel jpanel1 = new ImagePanel("f:my picture6f4703
26、95853e7f507bf480bb.jpg"); public StaffMain(String s) throws HeadlessException super(s);/ TODO Auto-generated constructor stub Container c = getContentPane();c.setLayout(new BorderLayout();setLocation(283, 84);setSize(800, 600);init();c.add(jpanel1);j1.addActionListener(this);j2.addActionListene
27、r(this);j3.addActionListener(this);j4.addActionListener(this);j5.addActionListener(this);j6.addActionListener(this);setResizable(false);setVisible(true);void init() jpanel1.setLayout(null);j1.setBounds(410, 100, 350, 30);j2.setBounds(380, 140, 350, 30);j3.setBounds(420, 180, 350, 30);j4.setBounds(39
28、0, 220, 350, 30);j5.setBounds(420, 260, 350, 30);j6.setBounds(390, 300, 350, 30); label.setBounds(185, 20, 450, 35); j1.setForeground(Color.white); j2.setForeground(Color.white); j3.setForeground(Color.white);j4.setForeground(Color.white);j5.setForeground(Color.white);j6.setForeground(Color.white);
29、label.setForeground(Color.white); j1.setContentAreaFilled(false); j1.setBorder(null);j2.setContentAreaFilled(false);j2.setBorder(null);j3.setContentAreaFilled(false);j3.setBorder(null);j4.setContentAreaFilled(false);j4.setBorder(null);j5.setContentAreaFilled(false);j5.setBorder(null);j6.setContentAr
30、eaFilled(false);j6.setBorder(null);jpanel1.add(j1);jpanel1.add(j2);jpanel1.add(j3);jpanel1.add(j4);jpanel1.add(j5);jpanel1.add(j6);jpanel1.add(label);j1.setFont(fnt);j2.setFont(fnt);j3.setFont(fnt);j4.setFont(fnt);j5.setFont(fnt);j6.setFont(fnt);label.setFont(new Font(" 方正舒体 ", Font.BOLD,
31、40); public void actionPerformed(ActionEvent e) / TODO Auto-generated method stubif (e.getSource() = j1) dispose();new StaffAdd(" 增加员工信息 "); else if (e.getSource() = j2) dispose();new StaffUpdate(" 修改员工信息 "); else if (e.getSource() = j3) dispose();new StaffDelete(); else if (e.ge
32、tSource() = j4) dispose();new StaffQuery(" 查找员工信息"); else if (e.getSource() = j5) dispose();new StaffAll(); else if (e.getSource() = j6) new About();public static void main(String args) / TODO Auto-generated method stubnew StaffMain(" 员工信息管理系统");/ 增加员工信息import java.awt.BorderLayo
33、ut;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GridLayout;import java.awt.HeadlessException;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Res
34、ultSet;import java.sql.SQLException;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JTextField;class StaffAdd extends JFrame imple
35、ments ActionListener JPanel jpanel1 = new ImagePanel("f:my picture1.jpg");JLabel j1 = new JLabel("编号:");JLabel j2 = new JLabel("姓名:");JLabel j3 = new JLabel("性别");JLabel j4 = new JLabel("年龄:");JLabel j5 = new JLabel("工资:");JLabel j6 = new J
36、Label("地址:");JLabel j7 = new JLabel(" 部门 :");JRadioButton radioButton1 = new JRadioButton("男");JRadioButton radioButton2 = new JRadioButton("女");JButton but1 = new JButton("添加");JButton but2 = new JButton("关闭");JButton but3 = new JButton(&q
37、uot; 返回主菜单");Font fnt=new Font(" 方正舒体 ",Font.BOLD,25);JTextField text1 = new JTextField(10);JTextField text2 = new JTextField(10);JTextField text3 = new JTextField(10);JTextField text4 = new JTextField(10);JTextField text5 = new JTextField(10);JTextField text6 = new JTextField(10);But
38、tonGroup bg = new ButtonGroup();public StaffAdd(String s) throws HeadlessException super(s);/ TODO Auto-generated constructor stubStaffInit();jpanel1.add(j1);jpanel1.add(text1);jpanel1.add(j2);jpanel1.add(text2);jpanel1.add(j3);bg.add(radioButton1);bg.add(radioButton2);jpanel1.add(radioButton1);jpan
39、el1.add(radioButton2);jpanel1.add(j4);jpanel1.add(text3);jpanel1.add(j5);jpanel1.add(text4);jpanel1.add(j6);jpanel1.add(text5);jpanel1.add(j7);jpanel1.add(text6);jpanel1.add(but1);jpanel1.add(but2);jpanel1.add(but3);this.getContentPane().add(jpanel1);but1.addActionListener(this);but2.addActionListen
40、er(this);but3.addActionListener(this);Toolkit kit = Toolkit.getDefaultToolkit();Dimension screen = kit.getScreenSize();int x = screen.width; /* 取得显示器窗口的宽度*/int y = screen.height;setSize(820, 620);int xcenter = (x - 820) / 2;int ycenter = (y - 620) / 2;setLocation(xcenter, ycenter);setResizable(false
41、);setVisible(true);public void StaffInit()jpanel1.setLayout(null);j1.setFont(fnt);j2.setFont(fnt);j3.setFont(fnt);j4.setFont(fnt);j5.setFont(fnt);j6.setFont(fnt);j7.setFont(fnt);text1.setFont(fnt);text2.setFont(fnt);text3.setFont(fnt);text4.setFont(fnt);text5.setFont(fnt);text6.setFont(fnt);but1.set
42、Font(fnt);but2.setFont(fnt);but3.setFont(fnt);radioButton1.setFont(fnt);radioButton2.setFont(fnt);j1.setBounds(50,50,80,30);j2.setBounds(250,50,80,30);j4.setBounds(50,100,80,30);j5.setBounds(250,100,80,30);j6.setBounds(50,150,80,30);j7.setBounds(250,150,80,30);text1.setBounds(119,52,100,30);text2.se
43、tBounds(319,52,100,30);text3.setBounds(119,102,100,30);text4.setBounds(319,102,100,30);text5.setBounds(119,152,100,30);text6.setBounds(319,152,100,30);j3.setBounds(50,200,80,30);radioButton1.setBounds(150,203,85,30);radioButton2.setBounds(250,203,85,30);but1.setBounds(135,240,100,30);but2.setBounds(
44、135,290,100,30);but3.setBounds(95,340,170,30);text1.setOpaque(false);text1.setBorder(null);text2.setOpaque(false);text2.setBorder(null);text3.setOpaque(false);text3.setBorder(null);text4.setOpaque(false);text4.setBorder(null);text5.setOpaque(false);text5.setBorder(null);text6.setOpaque(false);text6.
45、setBorder(null);radioButton1.setContentAreaFilled(false);radioButton2.setContentAreaFilled(false);but1.setContentAreaFilled(false);but1.setBorder(null);but2.setContentAreaFilled(false);but2.setBorder(null);but3.setContentAreaFilled(false);but3.setBorder(null);j1.setForeground(Color.white);j2.setFore
46、ground(Color.white);j3.setForeground(Color.white);j4.setForeground(Color.white);j5.setForeground(Color.white);j6.setForeground(Color.white);j7.setForeground(Color.white);j1.setForeground(Color.white);text1.setForeground(Color.white);text2.setForeground(Color.white);text3.setForeground(Color.white);t
47、ext4.setForeground(Color.white);text5.setForeground(Color.white);text6.setForeground(Color.white);but1.setForeground(Color.white);but2.setForeground(Color.white);but3.setForeground(Color.white);radioButton1.setForeground(Color.white);radioButton2.setForeground(Color.white);public void actionPerforme
48、d(ActionEvent e) / TODO Auto-generated method stub DataBaseManager db = new DataBaseManager();String ID = text1.getText().trim();String sql = "select ID from staff"int flag = 0;if (e.getSource() = but1) ResultSet rs = db.getResult(sql);try while(rs.next()if (ID.equals(rs.getString(1) flag
49、= 1; break; catch (SQLException e1) / TODO Auto-generated catch blocke1.printStackTrace();if (flag = 1) JOptionPane.showMessageDialog(this, " 编号相同不能插入 ");text1.setText("");text2.setText("");text3.setText("");text4.setText("");text5.setText("&quo
50、t;);text6.setText("");if (flag = 0) init(); else if (e.getSource() = but2) System.exit(0); else this.hide();new StaffMain(" 员工信息管理系统");public void init() String sql;String s1 = text1.getText().trim();String s2 = text2.getText().trim();String s3 = radioButton1.getText();String s4
51、= radioButton2.getText();String s5 = text3.getText().trim();String s6 = text4.getText().trim();String s7 = text5.getText().trim();String s8 = text6.getText().trim(); if (radioButton1.isSelected() sql = "insert into staff values('" + s1 + "','" + s2 + "','
52、" + s3"','" + s5 +"','" + s6 + "','"+ s7 + "','" + s8 + "')"提示 ",new DataBaseManager().updateSql(sql);JOptionPane.showMessageDialog(this, " 添加成功!JOptionPane.INFORMATION_MESSAGE);text1.setText("&
53、quot;)text2.setText("")text3.setText("")text4.setText("")text5.setText("")text6.setText("") else if (radioButton2.isSelected() sql = "insert into staff values('" + s1 + "','" + s2 + "','" + s4 new Dat
54、aBaseManager().updateSql(sql);"','" + s5 +"','" + s6 + "','"+ s7 + "','" + s8 + "')"JOptionPane.showMessageDialog(this, " 添加成功! ", " 提示 ",JOptionPane.INFORMATION_MESSAGE);text1.setText("&qu
55、ot;);text2.setText("");text3.setText("");text4.setText("");text5.setText("");text6.setText(""); else JOptionPane.showMessageDialog(this, " 请选择性别 ", " 提示 ", JOptionPane.INFORMATION_MESSAGE);public static void main(String args) new
56、StaffAdd(" 增加员工信息");/修改员工信息import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GridLayout;import java.awt.HeadlessException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import
57、 java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.
58、JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;class StaffUpdate extends JFrame implements ActionListener, ItemListener private JComboBox jcb;private JLabel jlabel = new JLabel(" 按编号修改:");private JLabel j1 =new JLabel("姓名: ");private JLabel j2 = new JLabel(" 性别 : ");private JLabel j3 =new JLabel("年龄: ");private JLabel j4 =new JLabel("工资: ");private JLabel j5 =new JLabel("地址: ");private JLabel j6 =new JLabel("部门: ");pri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年锡林郭勒盟正蓝旗教师招聘笔试参考试题及答案解析
- 河北对口单招医学类职业技能(生理学基础)知识点必考必练300题(含答案)
- 2025年平安县中小学教师招聘笔试参考试题及答案解析
- 2025年襄樊老河口市教师招聘参考题库及答案解析
- 失眠症常见症状及护理规范
- 2025年血糖仪保密合同协议
- 2025年赤峰阿鲁科尔沁旗市教师招聘参考题库及答案解析
- 2025年虚拟数字人形象使用权转让协议
- 2025年汝阳县中小学教师招聘笔试参考试题及答案解析
- 2025年小学教师资格证考试(地理学科知识与教学能力)模拟卷后附答案
- 中考英语短语冀教版汇总
- 办公用品运输供货方案
- 噬血细胞综合症护理查房
- 《Java从入门到精通》课件
- 钢筋焊接培训课件
- 海南省冷链物流发展现状及对策研究
- 眼科学第一节绪论眼科学基础
- 过程能力分析表CPK
- 新版中国驾照英文翻译模板
- 水质在线监测系统运维技术方案
- 初中艺术鄂教七年级上册漫步艺术长廊舞剧欣赏《永不消逝的电波》
评论
0/150
提交评论