Java课程设计-人事管理系统的设计与实现.doc

上传人:飞****2 文档编号:78939311 上传时间:2023-03-19 格式:DOC 页数:15 大小:498.50KB
返回 下载 相关 举报
Java课程设计-人事管理系统的设计与实现.doc_第1页
第1页 / 共15页
Java课程设计-人事管理系统的设计与实现.doc_第2页
第2页 / 共15页
点击查看更多>>
资源描述

《Java课程设计-人事管理系统的设计与实现.doc》由会员分享,可在线阅读,更多相关《Java课程设计-人事管理系统的设计与实现.doc(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、课 程 设 计 课程名称 Java语言课程设计 题目名称 人事管理系统的设计与实现 学生学院 专业班级_ _ _学 号 学生姓名 指导教师 2012年6月8日一、 设计内容自学Swing图形界面设计和数据库程序设计。开发用于某单位的人事管理系统。该系统要求实现以下功能:员工信息管理(包括:员工信息一览表、新员工的建立、修改、删除)二、 设计方案1、使用Netbeans IDE 7.1和SQL Server2000进行编译。2、代码如下:登录按钮代码: private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt)

2、private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) String user = jTextField1.getText().trim(); String password = jTextField2.getText().trim(); if (user.equals(wsm) & password.equals(wsm) new yuangongxinxiguanli().setVisible(true); setVisible(false); else JOptionPane.showMessageDial

3、og(null, 请正确输入!); public static void main(String args) java.awt.EventQueue.invokeLater(new Runnable() public void run() new denglu().setVisible(true); ); 员工信息关系系统界面:package 人事管理系统;public class yuangongxinxiguanli extends javax.swing.JFrame public yuangongxinxiguanli() initComponents(); setLocation(4

4、50,220); SuppressWarnings(unchecked) / private void initComponents() jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); setDe

5、faultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText(查询员工信息); jButton1.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton1ActionPerformed(evt); ); jButton2.setText(添加员工信息); jButton2.addActionListener(n

6、ew java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton2ActionPerformed(evt); ); jButton3.setText(删除员工信息); jButton3.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton3ActionPerformed

7、(evt); ); jLabel1.setFont(new java.awt.Font(宋体, 0, 24); / NOI18N jLabel1.setText(员工信息管理系统); jButton4.setText(修改员工信息); jButton4.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton4ActionPerformed(evt); ); jButton5.setText(退出系统); jB

8、utton5.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton5ActionPerformed(evt); ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layo

9、ut.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(91, 91, 91) .addGroup(layout.createParallelGroup(javax.swing.Gro

10、upLayout.Alignment.LEADING, false) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2, javax.s

11、wing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZ

12、E, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(47, 47, 47) .addComponent(jLabel1) .addContainerGap(52, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(14, 14, 14)

13、 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE

14、LATED) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addPr

15、eferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRE

16、D_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(36, Short.MAX_VALUE) ); pack(); / private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) chaxun ch=new chaxun(); ch.setVisible(true); ch.setLocation(400,220); setVisible(false); private void jButton2ActionPerformed(ja

17、va.awt.event.ActionEvent evt) tianjia ti=new tianjia(); ti.setVisible(true); ti.setLocation(400,220); setVisible(false);/ TODO add your handling code here: private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) xiugai xi=new xiugai(); xi.setVisible(true); xi.setLocation(400,220); setVi

18、sible(false);/ TODO add your handling code here: private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) shanchu sh=new shanchu(); sh.setVisible(true); sh.setLocation(400,220); setVisible(false); private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) System.exit(0); public

19、 static void main(String args) java.awt.EventQueue.invokeLater(new Runnable() public void run() new yuangongxinxiguanli().setVisible(true); ); / Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; pri

20、vate javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; / End of variables declaration 查询按钮代码:可选择项查询按钮代码: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) try String xuanze= jComboBox1.getSelectedItem().toString().trim(); Strin

21、g tianxie=jTextField1.getText().trim(); Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver); String url=jdbc:microsoft:sqlserver: + /127.0.0.1:1433;DatabaseName=员工信息管理库; Connection con=DriverManager.getConnection(url,sa,); java.sql.Statement stmt=con.createStatement(); ResultSet rs=stmt.exec

22、uteQuery(select * from 员工 where +xuanze+=+tianxie+); DefaultTableModel dt=(DefaultTableModel) jTable1.getModel(); dt.getDataVector().clear(); dt.fireTableDataChanged(); while(rs.next () Vector v1=new Vector(); v1.add(rs.getString(1); v1.add(rs.getString(2); v1.add(rs.getString(3); v1.add(rs.getStrin

23、g(4); v1.add(rs.getString(5); v1.add(rs.getString(6); v1.add(rs.getString(7); dt.addRow(v1); dt.fireTableDataChanged(); rs.close(); stmt.close(); con.close(); catch (ClassNotFoundException ex) ex.getMessage(); catch(SQLException ex) ex.getMessage(); 查询全部信息按钮代码: private void jButton3ActionPerformed(j

24、ava.awt.event.ActionEvent evt) try Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver); String url=jdbc:microsoft:sqlserver: + /127.0.0.1:1433;DatabaseName=员工信息管理库; Connection con=DriverManager.getConnection(url,sa,); java.sql.Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQu

25、ery(select * from 员工); DefaultTableModel dt=(DefaultTableModel) jTable1.getModel(); dt.getDataVector().clear(); while(rs.next () Vector v1=new Vector(); v1.add(rs.getString(1); v1.add(rs.getString(2); v1.add(rs.getString(3); v1.add(rs.getString(4); v1.add(rs.getString(5); v1.add(rs.getString(6); v1.

26、add(rs.getString(7); dt.addRow(v1); dt.fireTableDataChanged(); rs.close(); stmt.close(); con.close(); catch (ClassNotFoundException ex) Logger.getLogger(chaxun.class.getName().log(Level.SEVERE, null, ex); catch(SQLException ex) ex.getMessage(); public static void main(String args) java.awt.EventQueu

27、e.invokeLater(new Runnable() public void run() new chaxun().setVisible(true); ); 添加界面代码: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) try String yuangonghao = jtf_yuangonghao.getText().trim(); String phonenumber = jtf_phonenumber.getText().trim(); String name = jtf_name.getTe

28、xt().trim(); String age = jtf_age.getText().trim(); String sex = jtf_sex.getText().trim(); String post = jtf_post.getText().trim(); String pay = jtf_pay.getText().trim(); Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver); String url = jdbc:microsoft:sqlserver: + /127.0.0.1:1433;DatabaseNam

29、e=员工信息管理库; Connection con = DriverManager.getConnection(url, sa, ); String str=insert into 员工 values(?,?,?,?,?,?,?); PreparedStatement stmt = con.prepareStatement(str); stmt.setString(1,yuangonghao); stmt.setString(2,name); stmt.setString(3,age); stmt.setString(4,sex); stmt.setString(5,post); stmt.s

30、etString(6,phonenumber); stmt.setString(7,pay); ResultSet rs=stmt.executeQuery(); rs.close(); stmt.close(); con.close(); catch (ClassNotFoundException ex) catch (SQLException ex) if (ex.getSQLState().equals(HY000) JOptionPane.showMessageDialog(null, 添加成功); if(ex.getSQLState().equals(23000) JOptionPa

31、ne.showMessageDialog(null, 已经存在该编号的员工,添加失败); public static void main(String args) java.awt.EventQueue.invokeLater(new Runnable() public void run() new tianjia().setVisible(true); ); 修改界面代码: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) try String xuanze= jComboBox1.getSelected

32、Item().toString().trim(); String tianxie=jTextField2.getText().trim();/hao String tianxie2=jTextField3.getText().trim();/xie if(tianxie2.equals() JOptionPane.showMessageDialog(null, 请正确输入!); else Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver); String url=jdbc:microsoft:sqlserver: + /127.0.0.1:1433;DatabaseName=员工信息管理库; Connection con=DriverManager.getConnection(url,sa,); java.sql.Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(update 员工 set +xuanze+=+tianxie2+

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁