Java课程设计人事管理系统的设计与实现.docx
- 文档编号:23059593
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:20
- 大小:217.16KB
Java课程设计人事管理系统的设计与实现.docx
《Java课程设计人事管理系统的设计与实现.docx》由会员分享,可在线阅读,更多相关《Java课程设计人事管理系统的设计与实现.docx(20页珍藏版)》请在冰豆网上搜索。
Java课程设计人事管理系统的设计与实现
课程设计
课程名称Java语言课程设计
题目名称人事管理系统的设计与实现
学生学院
专业班级_________
学号
学生姓名
指导教师
2012年6月8日
一、设计内容
自学Swing图形界面设计和数据库程序设计。
开发用于某单位的人事管理系统。
该系统要求实现以下功能:
员工信息管理(包括:
员工信息一览表、新员工的建立、修改、删除)
二、设计方案
1、使用NetbeansIDE7.1和SQLServer2000进行编译。
2、代码如下:
登录按钮代码:
privatevoidjTextField1ActionPerformed(java.awt.event.ActionEventevt){
}
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
Stringuser=jTextField1.getText().trim();
Stringpassword=jTextField2.getText().trim();
if(user.equals("wsm")&&password.equals("wsm")){
newyuangongxinxiguanli().setVisible(true);
setVisible(false);
}else{
JOptionPane.showMessageDialog(null,"请正确输入!
");
}
}
publicstaticvoidmain(Stringargs[]){
java.awt.EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
newdenglu().setVisible(true);
}
});
}
员工信息关系系统界面:
package人事管理系统;
publicclassyuangongxinxiguanliextendsjavax.swing.JFrame{
publicyuangongxinxiguanli(){
initComponents();
setLocation(450,220);
}
@SuppressWarnings("unchecked")
//
privatevoidinitComponents(){
jButton1=newjavax.swing.JButton();
jButton2=newjavax.swing.JButton();
jButton3=newjavax.swing.JButton();
jLabel1=newjavax.swing.JLabel();
jButton4=newjavax.swing.JButton();
jButton5=newjavax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("查询员工信息");
jButton1.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jButton1ActionPerformed(evt);
}
});
jButton2.setText("添加员工信息");
jButton2.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jButton2ActionPerformed(evt);
}
});
jButton3.setText("删除员工信息");
jButton3.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jButton3ActionPerformed(evt);
}
});
jLabel1.setFont(newjava.awt.Font("宋体",0,24));//NOI18N
jLabel1.setText("员工信息管理系统");
jButton4.setText("修改员工信息");
jButton4.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jButton4ActionPerformed(evt);
}
});
jButton5.setText("退出系统");
jButton5.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jButton5ActionPerformed(evt);
}
});
javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.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.GroupLayout.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.swing.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_SIZE,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)
.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.UNRELATED)
.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)
.addPreferredGap(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.PREFERRED_SIZE,33,javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(36,Short.MAX_VALUE))
);
pack();
}//
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
chaxunch=newchaxun();
ch.setVisible(true);
ch.setLocation(400,220);
setVisible(false);
}
privatevoidjButton2ActionPerformed(java.awt.event.ActionEventevt){
tianjiati=newtianjia();
ti.setVisible(true);
ti.setLocation(400,220);
setVisible(false);//TODOaddyourhandlingcodehere:
}
privatevoidjButton4ActionPerformed(java.awt.event.ActionEventevt){
xiugaixi=newxiugai();
xi.setVisible(true);
xi.setLocation(400,220);
setVisible(false);//TODOaddyourhandlingcodehere:
}
privatevoidjButton3ActionPerformed(java.awt.event.ActionEventevt){
shanchush=newshanchu();
sh.setVisible(true);
sh.setLocation(400,220);
setVisible(false);
}
privatevoidjButton5ActionPerformed(java.awt.event.ActionEventevt){
System.exit(0);
}
publicstaticvoidmain(Stringargs[]){
java.awt.EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
newyuangongxinxiguanli().setVisible(true);
}
});
}
//Variablesdeclaration-donotmodify
privatejavax.swing.JButtonjButton1;
privatejavax.swing.JButtonjButton2;
privatejavax.swing.JButtonjButton3;
privatejavax.swing.JButtonjButton4;
privatejavax.swing.JButtonjButton5;
privatejavax.swing.JLabeljLabel1;
//Endofvariablesdeclaration
}
查询按钮代码:
可选择项查询按钮代码:
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
try{
Stringxuanze=jComboBox1.getSelectedItem().toString().trim();
Stringtianxie=jTextField1.getText().trim();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Stringurl="jdbc:
microsoft:
sqlserver:
"
+"//127.0.0.1:
1433;DatabaseName=员工信息管理库";
Connectioncon=DriverManager.getConnection(url,"sa","900526");
java.sql.Statementstmt=con.createStatement();
ResultSetrs=stmt.executeQuery("select*from员工where"+xuanze+"='"+tianxie+"'");
DefaultTableModeldt=(DefaultTableModel)jTable1.getModel();
dt.getDataVector().clear();
dt.fireTableDataChanged();
while(rs.next())
{Vectorv1=newVector();
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.add(rs.getString(7));
dt.addRow(v1);
}
dt.fireTableDataChanged();
rs.close();
stmt.close();
con.close();
}catch(ClassNotFoundExceptionex){
ex.getMessage();
}catch(SQLExceptionex){
ex.getMessage();
}
}
查询全部信息按钮代码:
privatevoidjButton3ActionPerformed(java.awt.event.ActionEventevt){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Stringurl="jdbc:
microsoft:
sqlserver:
"
+"//127.0.0.1:
1433;DatabaseName=员工信息管理库";
Connectioncon=DriverManager.getConnection(url,"sa","900526");
java.sql.Statementstmt=con.createStatement();
ResultSetrs=stmt.executeQuery("select*from员工");
DefaultTableModeldt=(DefaultTableModel)jTable1.getModel();
dt.getDataVector().clear();
while(rs.next())
{Vectorv1=newVector();
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.add(rs.getString(7));
dt.addRow(v1);
}
dt.fireTableDataChanged();
rs.close();
stmt.close();
con.close();
}catch(ClassNotFoundExceptionex){
Logger.getLogger(chaxun.class.getName()).log(Level.SEVERE,null,ex);
}catch(SQLExceptionex){
ex.getMessage();
}
}
publicstaticvoidmain(Stringargs[]){
java.awt.EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
newchaxun().setVisible(true);
}
});
}
添加界面代码:
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
try{
Stringyuangonghao=jtf_yuangonghao.getText().trim();
Stringphonenumber=jtf_phonenumber.getText().trim();
Stringname=jtf_name.getText().trim();
Stringage=jtf_age.getText().trim();
Stringsex=jtf_sex.getText().trim();
Stringpost=jtf_post.getText().trim();
Stringpay=jtf_pay.getText().trim();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Stringurl="jdbc:
microsoft:
sqlserver:
"
+"//127.0.0.1:
1433;DatabaseName=员工信息管理库";
Connectioncon=DriverManager.getConnection(url,"sa","900526");
Stringstr="insertinto员工values(?
?
?
?
?
?
?
)";
PreparedStatementstmt=con.prepareStatement(str);
stmt.setString(1,yuangonghao);
stmt.setString(2,name);
stmt.setString(3,age);
stmt.setString(4,sex);
stmt.setString(5,post);
stmt.setString(6,phonenumber);
stmt.setString(7,pay);
ResultSetrs=stmt.executeQuery();
rs.close();
stmt.close();
con.close();
}catch(ClassNotFoundExceptionex){
}catch(SQLExceptionex){
if(ex.getSQLState().equals("HY000")){
JOptionPane.showMessageDialog(null,"添加成功");
}
if((ex.getSQLState().e
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 课程设计 人事管理系统 设计 实现