员工信息管理系统实验报告

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

华侨大学厦门工学院

《面向对象程序设计实践》课程实验报告

(分组实验)

实验名称 __ 员工基本信息管理系统_ __

系部 __ 计算机科学与工程系_____

班级 ___ 软件3班____________

小组名称 ______ 第三组_____________

指导老师文欣

计算机科学与工程系

2014年06月12日

一、实验名称

员工基本信息管理系统

二、实验目的及任务要求

目的:对员工的信息进行有效的管理和储存

任务要求:对员工的信息进行增加,删除,查找,修改等功能

三、实验环境

eclipse.exe

四、实验内容

//注册用户

import javax.swing.*;

import java.awt.*;

import java.awt.Event.*;

import java.awt.event.ActionEvent;

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("用户注册");

lblUserName = 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('*');

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.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 actionPerformed(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("")) { 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, "该用户名已存在!", "Message",

JOptionPane.DEFAULT_OPTION);

}

else {

sql = "insert into user values(" + "'" + username + "'"

+ ",'" + password + "')";

db.updateSql(sql);

System.out.println(sql);

JOptionPane.showMessageDialog(null, "注册成功!", "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();

}

}

相关文档
最新文档