题目
1、问题描述
某高校有四类员工:教师、实验员、行政人员,教师兼行政人员;共有的信息包括:编号、姓名、性别、年龄等。其中,教师还包含的信息有:所在系部、专业、职称;实验员还包含的信息由:所在实验室、职务;行政人员还包含的信息有:政治面貌、职称等。
2、功能要求
(1)添加功能:程序能够任意添加上述四类人员的记录,可提供选择界面供用户选择所要添加的人员类别,要求员工的编号要唯一,如果添加了重复编号的记录时,则提示数据添加重复并取消添加。
(2)查询功能:可根据编号、姓名等信息对已添加的记录进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息。
(3)显示功能:可显示当前系统中所有记录,每条记录占据一行。
(4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。
(5)删除功能:主要实现对已添加的人员记录进行删除。如果当前系统中没有相应的人员记录,则提示“记录为空!”并返回操作;否则,输入要删除的人员的编号或姓名,根据所输入的信息删除该人员记录,如果没有找到该人员信息,则提示相应的记录不存。
(6)统计功能:能根据多种参数进行人员的统计。能统计四类人员数量以及总数,
统计男、女员工的数量。
(7)保存功能:可将当前系统中各类人员记录存入文件或数据库中,存入方式任意。
(8)读取功能:可将保存在文件或数据库中的人员信息读入到当前系统中,供用户进行使用。
3、问题的解决方案
根据系统功能要求,可以将问题解决分为以下步骤:
(1)应用系统分析,建立该系统的功能模块框图以及界面的组织和设计;
(2)分析系统中的各个实体及它们之间的关系;
(3)根据问题描述,设计系统的类层次;
(4)完成类层次中各个类的描述;
(5)完成类中各个成员函数的定义;
(6)完成系统的应用模块;
(7)功能调试;
(8)完成系统总结报告。
1.登陆界面设计
package com.artisan.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.artisan.dao.AdministrativeDao;
import com.artisan.dao.ExperimenterDao;
import com.artisan.dao.teacherDao;
import com.artisan.dao.teacherandxDao;
import com.artisan.model.Administrative;
import com.artisan.model.Experimenter;
import com.artisan.model.UserType;
import com.artisan.model.teacher;
import com.artisan.model.teacherandx;
import com.artisan.util.StringUtil;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Color;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class LoginFrm extends JFrame {
private JPanel contentPane;
private JTextField userNameTextField;
private JTextField passwordTextField;
private JComboBox userTypeComboBox;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginFrm frame = new LoginFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LoginFrm() {
setTitle("\u767B\u5F55\u754C\u9762");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 498, 340);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setLocationRelativeTo(null);
JLabel lblNewLabel = new JLabel("\u9AD8\u6821\u4EBA\u5458\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF");
lblNewLabel.setIcon(new ImageIcon(LoginFrm.class.getResource("/images/\u5728\u7C4D\u5B66\u751F\u7BA1\u7406.png")));
lblNewLabel.setFont(new Font("幼圆", Font.BOLD, 20));
lblNewLabel.setForeground(new Color(0, 0, 0));
JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D\uFF1A");
lblNewLabel_1.setIcon(new ImageIcon(LoginFrm.class.getResource("/images/\u7528\u6237.png")));
lblNewLabel_1.setFont(new Font("幼圆", Font.PLAIN, 16));
userNameTextField = new JTextField();
userNameTextField.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("\u5BC6 \u7801\uFF1A");
lblNewLabel_2.setIcon(new ImageIcon(LoginFrm.class.getResource("/images/\u5BC6\u7801.png")));
lblNewLabel_2.setFont(new Font("幼圆", Font.PLAIN, 16));
passwordTextField = new JTextField();
passwordTextField.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("\u7528\u6237\u7C7B\u578B\uFF1A");
lblNewLabel_3.setIcon(new ImageIcon(LoginFrm.class.getResource("/images/\u5B66\u751F\u7BA1\u7406.png")));
lblNewLabel_3.setFont(new Font("幼圆", Font.PLAIN, 16));
userTypeComboBox = new JComboBox();
userTypeComboBox.setModel(new DefaultComboBoxModel(new UserType[] {UserType.ADMIN, UserType.TEACHER, UserType.STUDENT,UserType.AND}));
userTypeComboBox.setFont(new Font("幼圆", Font.PLAIN, 14));
JButton loginButton = new JButton("\u767B\u5F55");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
loginAct(ae);
}
});
loginButton.setIcon(new ImageIcon(LoginFrm.class.getResource("/images/\u767B\u5F55.png")));
loginButton.setFont(new Font("幼圆", Font.PLAIN, 14));
JButton resetButton = new JButton("\u91CD\u7F6E");
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
restValue(ae);
}
});
resetButton.setIcon(new ImageIcon(LoginFrm.class.getResource("/images/\u91CD\u7F6E.png")));
resetButton.setFont(new Font("幼圆", Font.PLAIN, 14));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(74)
.addComponent(loginButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 168, Short.MAX_VALUE)
.addComponent(resetButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
.addGap(38))
.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
.addGap(100)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
.addGap(71))
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(userNameTextField, GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))
.addGroup(gl_contentPane.createSequentialGroup()
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(userTypeComboBox, 0, 181, Short.MAX_VALUE))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel_2)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(passwordTextField, GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)))
.addGap(81))))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(45)
.addComponent(lblNewLabel)
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(userNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(passwordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_3)
.addComponent(userTypeComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(loginButton)
.addComponent(resetButton))
.addContainerGap())
);
contentPane.setLayout(gl_contentPane);
}
protected void loginAct(ActionEvent ae) {
// TODO Auto-generated method stub
String userName=userNameTextField.getText().toString();
String password=passwordTextField.getText().toString();
UserType selectedItem=(UserType)userTypeComboBox.getSelectedItem();
if(StringUtil.isEmpty(userName)){
JOptionPane.showMessageDialog(this,"用户名不能为空!");
return;
}
if(StringUtil.isEmpty(password)){
JOptionPane.showMessageDialog(this,"密码不能为空!");
return;
}
teacher admin=null;
Experimenter admin1=null;
Administrative admin2=null;
teacherandx admin3=null;
if("教师".equals(selectedItem.getName())) {
teacherDao adminDao=new teacherDao();
teacher adminTmp=new teacher();
adminTmp.setName(userName);
adminTmp.setPassword(password);
admin=adminDao.login(adminTmp);
if(admin==null) {
JOptionPane.showMessageDialog(this, "用户名或密码或用户类型错误!");
return;
}
JOptionPane.showMessageDialog(this, "欢迎【"+selectedItem.getName()+"】:"+admin.getName()+"登录本系统!");
this.dispose();
new MainFrm(selectedItem, admin).setVisible(true);//显示隐藏组件
}else if("实验员".equals(selectedItem.getName())) {
ExperimenterDao adminDao=new ExperimenterDao();
Experimenter adminTmp=new Experimenter();
adminTmp.setName(userName);
adminTmp.setPassword(password);
admin1=adminDao.login(adminTmp);
if(admin1==null) {
JOptionPane.showMessageDialog(this, "用户名或密码或用户类型错误!");
return;
}
JOptionPane.showMessageDialog(this, "欢迎【"+selectedItem.getName()+"】:"+admin1.getName()+"登录本系统!");
this.dispose();
new MainFrm(selectedItem, admin1).setVisible(true);
}else if("行政人员".equals(selectedItem.getName())) {
AdministrativeDao adminDao=new AdministrativeDao();
Administrative adminTmp=new Administrative();
adminTmp.setName(userName);
adminTmp.setPassword(password);
admin2=adminDao.login(adminTmp);
if(admin2==null) {
JOptionPane.showMessageDialog(this, "用户名或密码或用户类型错误!");
return;
}
JOptionPane.showMessageDialog(this, "欢迎【"+selectedItem.getName()+"】:"+admin2.getName()+"登录本系统!");
this.dispose();
new MainFrm(selectedItem, admin2).setVisible(true);
}else {
teacherandxDao adminDao=new teacherandxDao();
teacherandx adminTmp=new teacherandx();
adminTmp.setName(userName);
adminTmp.setPassword(password);
admin3=adminDao.login(adminTmp);
if(admin3==null) {
JOptionPane.showMessageDialog(this, "用户名或密码或用户类型错误!");
return;
}
JOptionPane.showMessageDialog(this, "欢迎【"+selectedItem.getName()+"】:"+admin3.getName()+"登录本系统!");
this.dispose();
new MainFrm(selectedItem, admin3).setVisible(true);
}
}
protected void restValue(ActionEvent ae) {
// TODO Auto-generated method stub
userNameTextField.setText("");
passwordTextField.setText("");
userTypeComboBox.setSelectedIndex(0);
}
}
运行效果图如下:
2.登陆后主界面设计
package com.artisan.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.artisan.model.UserType;
import com.artisan.util.allpeople;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.net.URI;
import java.awt.event.ActionEvent;
import javax.swing.JDesktopPane;
import java.awt.Color;
import java.awt.Desktop;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class MainFrm extends JFrame {
private JPanel contentPane;
private JDesktopPane desktopPane;
public static UserType userType;
public static Object userObject;
private JTextField xttextField;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// MainFrm frame = new MainFrm();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public MainFrm(UserType userType,Object userObject) {
this.userType=userType;
this.userObject=userObject;
setTitle("\u4FE1\u606F\u7CFB\u7EDF\u4E3B\u754C\u9762");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 864, 478);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu mnNewMenu = new JMenu("\u7CFB\u7EDF\u8BBE\u7F6E");
mnNewMenu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/Settings.png")));
menuBar.add(mnNewMenu);
JMenuItem mntmNewMenuItem = new JMenuItem("\u4FEE\u6539\u5BC6\u7801");
mntmNewMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
editPassword(ae);
}
});
mntmNewMenuItem.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u4FEE\u6539\u5BC6\u7801.png")));
mnNewMenu.add(mntmNewMenuItem);
JMenuItem mntmNewMenuItem_1 = new JMenuItem("\u9000\u51FA\u7CFB\u7EDF");
mntmNewMenuItem_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(MainFrm.this, "确定退出么?")==JOptionPane.OK_OPTION) {
System.exit(0);
}
}
});
mntmNewMenuItem_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u9000\u51FA\u7CFB\u7EDF.png")));
mnNewMenu.add(mntmNewMenuItem_1);
JMenu mnNewMenu_2 = new JMenu("\u4FE1\u606F\u7BA1\u7406");
mnNewMenu_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u73ED\u7EA7\u7BA1\u7406.png")));
menuBar.add(mnNewMenu_2);
JMenuItem mntmNewMenuItem_4 = new JMenuItem("\u6DFB\u52A0\u4EBA\u5458");
mntmNewMenuItem_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if("教师".equals(MainFrm.userType.getName())) {
AddteacherFrm editPasswordFrm=new AddteacherFrm();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}else if("实验员".equals(MainFrm.userType.getName())) {
AddexprimenterFrm editPasswordFrm=new AddexprimenterFrm();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}else if("行政人员".equals(MainFrm.userType.getName())) {
AddAdministrativeFrm editPasswordFrm=new AddAdministrativeFrm();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}else {
AddteacherandxFrm editPasswordFrm=new AddteacherandxFrm();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}
}
});
mntmNewMenuItem_4.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u6DFB\u52A01(1).png")));
mnNewMenu_2.add(mntmNewMenuItem_4);
JMenuItem mntmNewMenuItem_5 = new JMenuItem("\u4FE1\u606F\u5217\u8868");
mntmNewMenuItem_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if("教师".equals(MainFrm.userType.getName())) {
watchteacher editPasswordFrm=new watchteacher();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}else if("实验员".equals(MainFrm.userType.getName())) {
watchExperimenter editPasswordFrm=new watchExperimenter();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}else if("行政人员".equals(MainFrm.userType.getName())) {
watchAdministrative editPasswordFrm=new watchAdministrative();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}else {
watchteacherandx editPasswordFrm=new watchteacherandx();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}
}
});
mntmNewMenuItem_5.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u73ED\u7EA7\u5217\u8868.png")));
mnNewMenu_2.add(mntmNewMenuItem_5);
JMenu mnNewMenu_3 = new JMenu("\u5E2E\u52A9");
mnNewMenu_3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u5E2E\u52A9.png")));
menuBar.add(mnNewMenu_3);
JMenuItem mntmNewMenuItem_6 = new JMenuItem("\u95EE\u9898\u4E0E\u53CD\u9988");
mntmNewMenuItem_6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
aboutUs(ae);
}
});
mntmNewMenuItem_6.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u5173\u4E8E\u6211\u4EEC.png")));
mnNewMenu_3.add(mntmNewMenuItem_6);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
desktopPane = new JDesktopPane();
desktopPane.setBackground(new Color(173, 216, 230));
contentPane.add(desktopPane, BorderLayout.CENTER);
JLabel lblNewLabel = new JLabel("\u7CFB\u7EDF\u603B\u4EBA\u6570\uFF1A");
lblNewLabel.setVerticalAlignment(SwingConstants.BOTTOM);
lblNewLabel.setIcon(new ImageIcon(MainFrm.class.getResource("/images/\u5B66\u751F.png")));
lblNewLabel.setBounds(591, 345, 99, 15);
desktopPane.add(lblNewLabel);
xttextField = new JTextField();
xttextField.setHorizontalAlignment(SwingConstants.LEFT);
xttextField.setBounds(700, 342, 116, 21);
desktopPane.add(xttextField);
xttextField.setColumns(10);
setLocationRelativeTo(null);
allpeople s=new allpeople();
xttextField.setText(s.all());
}
protected void editPassword(ActionEvent ae) {
// TODO Auto-generated method stub
EditPasswordFrm editPasswordFrm=new EditPasswordFrm();
editPasswordFrm.setVisible(true);
desktopPane.add(editPasswordFrm);
}
protected void aboutUs(ActionEvent ae) {
// TODO Auto-generated method stub
String info="问题建议请联系:\n";
info +="QQ:3104073309";
JOptionPane.showMessageDialog(this, info);
}
}
3.登陆后修改密码
package com.artisan.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.artisan.dao.AdministrativeDao;
import com.artisan.dao.ExperimenterDao;
import com.artisan.dao.teacherDao;
import com.artisan.dao.teacherandxDao;
import com.artisan.model.Administrative;
import com.artisan.model.Experimenter;
import com.artisan.model.UserType;
import com.artisan.model.teacher;
import com.artisan.model.teacherandx;
import com.artisan.util.StringUtil;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class EditPasswordFrm extends JInternalFrame {
private JPanel contentPane;
private JTextField oldPasswordTextField;
private JTextField newPasswordTextField;
private JTextField confirmPasswordTextField;
private JLabel currentUserLabel;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// EditPasswordFrm frame = new EditPasswordFrm();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public EditPasswordFrm() {
setTitle("\u7BA1\u7406\u5458\u4FEE\u6539\u5BC6\u7801");
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setClosable(true);
setIconifiable(true);
JLabel lblNewLabel = new JLabel("\u539F\u5BC6\u7801\uFF1A");
lblNewLabel.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u5BC6\u7801.png")));
lblNewLabel.setFont(new Font("SimSun", Font.PLAIN, 12));
oldPasswordTextField = new JTextField();
oldPasswordTextField.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("\u65B0\u5BC6\u7801\uFF1A");
lblNewLabel_1.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u65B0\u5BC6\u78011.png")));
newPasswordTextField = new JTextField();
newPasswordTextField.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
lblNewLabel_2.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u65B0\u5BC6\u7801.png")));
confirmPasswordTextField = new JTextField();
confirmPasswordTextField.setColumns(10);
JButton submitButton = new JButton("\u786E\u8BA4\u4FEE\u6539");
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitEdit(e);
}
});
submitButton.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u786E\u8BA4\u4FEE\u6539.png")));
JButton resetButton = new JButton("\u53D6\u6D88\u4FEE\u6539");
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
resetValue(ae);
}
});
resetButton.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u53D6\u6D88\u4FEE\u6539\u540D\u79F0.png")));
JLabel lblNewLabel_3 = new JLabel("\u7528\u6237\u540D\uFF1A");
lblNewLabel_3.setIcon(new ImageIcon(EditPasswordFrm.class.getResource("/images/\u7528\u6237.png")));
currentUserLabel = new JLabel("");
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(73)
.addComponent(submitButton)
.addPreferredGap(ComponentPlacement.RELATED, 188, Short.MAX_VALUE)
.addComponent(resetButton, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
.addGap(41))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(103)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1)
.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_2)
.addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(currentUserLabel, GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
.addComponent(confirmPasswordTextField, GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
.addComponent(newPasswordTextField, GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
.addComponent(oldPasswordTextField, GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
.addGap(117))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(33)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_3)
.addComponent(currentUserLabel))
.addGap(25)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(lblNewLabel)
.addComponent(oldPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(20)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(lblNewLabel_1)
.addComponent(newPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(31)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(confirmPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_2))
.addPreferredGap(ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(submitButton)
.addComponent(resetButton))
.addGap(40))
);
contentPane.setLayout(gl_contentPane);
//获取登录时输入的用户名并显示
if("教师".equals(MainFrm.userType.getName())) {
teacher admin =(teacher)MainFrm.userObject;
currentUserLabel.setText("【教师】"+admin.getName());
}
if("实验员".equals(MainFrm.userType.getName())) {
Experimenter admin =(Experimenter)MainFrm.userObject;
currentUserLabel.setText("【实验员】"+admin.getName());
}
if("行政人员".equals(MainFrm.userType.getName())) {
Administrative admin =(Administrative)MainFrm.userObject;
currentUserLabel.setText("【行政人员】"+admin.getName());
}
if("教师兼行政人员".equals(MainFrm.userType.getName())) {
teacherandx admin =(teacherandx)MainFrm.userObject;
currentUserLabel.setText("【教师兼行政人员】"+admin.getName());
}
}
protected void submitEdit(ActionEvent e) {
// TODO Auto-generated method stub
String oldPassword=oldPasswordTextField.getText().toString();
String newPassword=newPasswordTextField.getText().toString();
String conformPassword=confirmPasswordTextField.getText().toString();
if(StringUtil.isEmpty(oldPassword)) {
JOptionPane.showMessageDialog(this, "请填写旧密码!");
return;
}
if(StringUtil.isEmpty(newPassword)) {
JOptionPane.showMessageDialog(this, "请填写新密码!");
return;
}
if(StringUtil.isEmpty(conformPassword)) {
JOptionPane.showMessageDialog(this, "请确认新密码!");
return;
}
if(!newPassword.equals(conformPassword)) {
JOptionPane.showMessageDialog(this, "两次密码输入不一致!");
return;
}
if("教师".equals(MainFrm.userType.getName())) {
teacherDao adminDao = new teacherDao();
teacher adminTmp= new teacher();
teacher admin=(teacher)MainFrm.userObject;
adminTmp.setName(admin.getName());
adminTmp.setPassword(oldPassword);
JOptionPane.showMessageDialog(this, adminDao.editPassword(adminTmp, newPassword));
return;
}else if("实验员".equals(MainFrm.userType.getName())) {
ExperimenterDao adminDao = new ExperimenterDao();
Experimenter adminTmp= new Experimenter();
Experimenter admin=(Experimenter)MainFrm.userObject;
adminTmp.setName(admin.getName());
adminTmp.setPassword(oldPassword);
JOptionPane.showMessageDialog(this, adminDao.editPassword(adminTmp, newPassword));
return;
}else if("行政人员".equals(MainFrm.userType.getName())) {
AdministrativeDao adminDao = new AdministrativeDao();
Administrative adminTmp= new Administrative();
Administrative admin=(Administrative)MainFrm.userObject;
adminTmp.setName(admin.getName());
adminTmp.setPassword(oldPassword);
JOptionPane.showMessageDialog(this, adminDao.editPassword(adminTmp, newPassword));
return;
}else {
teacherandxDao adminDao = new teacherandxDao();
teacherandx adminTmp= new teacherandx();
teacherandx admin=(teacherandx)MainFrm.userObject;
adminTmp.setName(admin.getName());
adminTmp.setPassword(oldPassword);
JOptionPane.showMessageDialog(this, adminDao.editPassword(adminTmp, newPassword));
return;
}
}
protected void resetValue(ActionEvent ae) {
// TODO Auto-generated method stub
oldPasswordTextField.setText("");
newPasswordTextField.setText("");
confirmPasswordTextField.setText("");
}
}
运行效果:
添加人员:
package com.artisan.view;
import java.awt.EventQueue;
import javax.swing.JInternalFrame;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.ImageIcon;
import javax.swing.JRadioButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import com.artisan.dao.teacherDao;
import com.artisan.model.teacher;
import com.artisan.util.StringUtil;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AddteacherFrm extends JInternalFrame {
private JTextField idtextField;
private JTextField nametextField;
private JTextField agetextField;
private JTextField zytextField;
private JTextField xbtextField;
private JTextField zctextField;
private JTextField passwordtextField;
private JRadioButton rdbtnNewRadioButton;
private JRadioButton rdbtnNewRadioButton_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AddteacherFrm frame = new AddteacherFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public AddteacherFrm() {
setClosable(true);
setIconifiable(true);
setTitle("\u6DFB\u52A0\u6210\u5458");
setBounds(100, 100, 582, 518);
JLabel lblNewLabel = new JLabel("\u5B66\u5DE5\u53F7\uFF1A");
lblNewLabel.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u5B66\u751F\u4FE1\u606F\u91C7\u96C6.png")));
idtextField = new JTextField();
idtextField.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("\u59D3\u540D\uFF1A\r\n");
lblNewLabel_1.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u7528\u6237.png")));
nametextField = new JTextField();
nametextField.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("\u6027\u522B\uFF1A");
lblNewLabel_2.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u6027\u522B.png")));
ButtonGroup buttonGroup=new ButtonGroup();
rdbtnNewRadioButton = new JRadioButton("\u7537");
rdbtnNewRadioButton.setSelected(true);
rdbtnNewRadioButton_1 = new JRadioButton("\u5973");
buttonGroup.add(rdbtnNewRadioButton);
buttonGroup.add(rdbtnNewRadioButton_1);
JLabel lblNewLabel_3 = new JLabel("\u5E74\u9F84\uFF1A");
lblNewLabel_3.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u5E74\u9F84.png")));
agetextField = new JTextField();
agetextField.setColumns(10);
JLabel lblNewLabel_4 = new JLabel("\u7CFB\u90E8\uFF1A");
lblNewLabel_4.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u9662\u7CFB\u90E8\u95E8.png")));
JLabel lblNewLabel_5 = new JLabel("\u4E13\u4E1A\uFF1A");
lblNewLabel_5.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u4E13\u4E1A\u6743\u5A01.png")));
zytextField = new JTextField();
zytextField.setColumns(10);
xbtextField = new JTextField();
xbtextField.setColumns(10);
JLabel lblNewLabel_6 = new JLabel("\u804C\u79F0\uFF1A");
lblNewLabel_6.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u804C\u79F0.png")));
JLabel lblNewLabel_7 = new JLabel("\u5BC6\u7801\uFF1A");
lblNewLabel_7.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u5BC6\u7801.png")));
zctextField = new JTextField();
zctextField.setColumns(10);
passwordtextField = new JTextField();
passwordtextField.setColumns(10);
JButton btnNewButton = new JButton("\u786E\u5B9A");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Addteacher(e);
}
});
btnNewButton.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u786E\u5B9A.png")));
JButton btnNewButton_1 = new JButton("\u91CD\u7F6E");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
restion(e);
}
});
btnNewButton_1.setIcon(new ImageIcon(AddteacherFrm.class.getResource("/images/\u91CD\u7F6E.png")));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(86)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_7, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_6, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_5, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(29)
.addComponent(rdbtnNewRadioButton, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(rdbtnNewRadioButton_1, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED))
.addGroup(groupLayout.createSequentialGroup()
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(nametextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(idtextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(agetextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(zytextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(xbtextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(zctextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(passwordtextField, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(btnNewButton_1, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE))))))
.addGap(121)))))))))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(52)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(idtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(nametextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(27)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(rdbtnNewRadioButton)
.addComponent(rdbtnNewRadioButton_1))
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_3)
.addComponent(agetextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_4)
.addComponent(xbtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_5)
.addComponent(zytextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(27)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_6)
.addComponent(zctextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(29)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_7)
.addComponent(passwordtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(btnNewButton)
.addComponent(btnNewButton_1))
.addGap(45))
);
getContentPane().setLayout(groupLayout);
}
protected void Addteacher(ActionEvent e) {
// TODO Auto-generated method stub
String id=idtextField.getText().toString();
String name=nametextField.getText().toString();
String sex=rdbtnNewRadioButton.isSelected() ? rdbtnNewRadioButton.getText().toString():rdbtnNewRadioButton_1.getText().toString();
String age=agetextField.getText().toString();
String xb=xbtextField.getText().toString();
String zy=zytextField.getText().toString();
String zc=zctextField.getText().toString();
String password=passwordtextField.getText().toString();
if(StringUtil.isEmpty(zc)||StringUtil.isEmpty(zy)||StringUtil.isEmpty(xb)||StringUtil.isEmpty(age)||StringUtil.isEmpty(sex)||StringUtil.isEmpty(name)||StringUtil.isEmpty(id)||StringUtil.isEmpty(password)) {
JOptionPane.showMessageDialog(this, "您还有信息尚未填写完整!");
return;
}
teacher t=new teacher();
t.setId(id);
t.setName(name);
t.setSex(sex);
t.setAge(age);
t.setXb(xb);
t.setZy(zy);
t.setZc(zc);
t.setPassword(password);
teacherDao te=new teacherDao();
JOptionPane.showMessageDialog(this,te.addclass(t) );
}
protected void restion(ActionEvent e) {
// TODO Auto-generated method stub
idtextField.setText("");
nametextField.setText("");
rdbtnNewRadioButton.setSelected(true);
agetextField.setText("");
xbtextField.setText("");
zytextField.setText("");
zctextField.setText("");
passwordtextField.setText("");
restion(e);
}
}
成员列表(包含查询,修改,删除,统计功能)
package com.artisan.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.table.DefaultTableModel;
import com.artisan.dao.AdministrativeDao;
import com.artisan.model.Administrative;
import com.artisan.util.StringUtil;
public class watchAdministrative extends JInternalFrame {
private JTable table;
private JTextField nametextField;
private JTextField agetextField;
private JTextField seachtextField;
private JTextField sextextField;
private JTextField zztextField;
private JTextField zctextField;
private JTextField allpeopletextField;
private JTextField mantextField;
private JTextField womentextField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
watchteacher frame = new watchteacher();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public watchAdministrative() {
setClosable(true);
setIconifiable(true);
setTitle("\u5B66\u751F\u5217\u8868");
setBounds(100, 100, 881, 713);
JScrollPane scrollPane = new JScrollPane();
JButton btnNewButton = new JButton("\u4FEE\u6539\u4FE1\u606F");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editact(e);
}
});
btnNewButton.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u786E\u5B9A.png")));
JButton btnNewButton_1 = new JButton("\u5220\u9664\u4FE1\u606F");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
delete(e);
}
});
btnNewButton_1.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u53D6\u6D88\u4FEE\u6539\u540D\u79F0.png")));
JLabel lblNewLabel_1 = new JLabel("\u59D3\u540D\uFF1A");
lblNewLabel_1.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u5B66\u751F\u7BA1\u7406.png")));
nametextField = new JTextField();
nametextField.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("\u5E74\u9F84\uFF1A");
lblNewLabel_2.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u5E74\u9F84.png")));
agetextField = new JTextField();
agetextField.setColumns(10);
seachtextField = new JTextField();
seachtextField.setColumns(10);
JButton btnNewButton_2 = new JButton("\u67E5\u8BE2");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Administrative cs=new Administrative();
cs.setId(seachtextField.getText().toString());
setTable(cs);
}
});
btnNewButton_2.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u67E5\u8BE2.png")));
JLabel lblNewLabel = new JLabel("\u6027\u522B:");
lblNewLabel.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u6027\u522B.png")));
sextextField = new JTextField();
sextextField.setColumns(10);
JLabel lblNewLabel_4 = new JLabel("\u653F\u6CBB\u9762\u8C8C\uFF1A");
lblNewLabel_4.setFont(new Font("宋体", Font.PLAIN, 7));
lblNewLabel_4.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u4E13\u4E1A\u6743\u5A01.png")));
zztextField = new JTextField();
zztextField.setColumns(10);
JLabel lblNewLabel_5 = new JLabel("\u804C\u79F0\uFF1A");
lblNewLabel_5.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u804C\u79F0.png")));
zctextField = new JTextField();
zctextField.setColumns(10);
JLabel lblNewLabel_7 = new JLabel("\u603B\u4EBA\u6570\uFF1A");
lblNewLabel_7.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u7528\u6237\u5217\u8868.png")));
allpeopletextField = new JTextField();
allpeopletextField.setColumns(10);
JLabel lblNewLabel_8 = new JLabel("\u7537\u8001\u5E08\u603B\u4EBA\u6570\uFF1A");
lblNewLabel_8.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u7537.png")));
mantextField = new JTextField();
mantextField.setColumns(10);
JLabel lblNewLabel_9 = new JLabel("\u5973\u8001\u5E08\u603B\u4EBA\u6570\uFF1A\r\n");
lblNewLabel_9.setIcon(new ImageIcon(watchteacher.class.getResource("/images/\u5973.png")));
womentextField = new JTextField();
womentextField.setColumns(10);
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(38)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(seachtextField, GroupLayout.PREFERRED_SIZE, 287, GroupLayout.PREFERRED_SIZE)
.addGap(117)
.addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE))
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 772, GroupLayout.PREFERRED_SIZE)))
.addGroup(groupLayout.createSequentialGroup()
.addGap(24)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(sextextField))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(nametextField, GroupLayout.PREFERRED_SIZE, 247, GroupLayout.PREFERRED_SIZE)))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(zztextField, GroupLayout.PREFERRED_SIZE, 251, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_5, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(zctextField, GroupLayout.PREFERRED_SIZE, 248, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addComponent(btnNewButton_1)
.addComponent(btnNewButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(53))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(agetextField, 247, 247, 247)
.addGap(207)))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_7, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
.addGap(63))
.addComponent(lblNewLabel_8, GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_9)
.addPreferredGap(ComponentPlacement.RELATED)))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addComponent(allpeopletextField, GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
.addComponent(womentextField))
.addComponent(mantextField, 149, 149, 149))))
.addGap(35))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(36)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(seachtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(btnNewButton_2))
.addGap(43)
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 243, GroupLayout.PREFERRED_SIZE)
.addGap(38)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(nametextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(sextextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(btnNewButton)
.addComponent(lblNewLabel_7)
.addComponent(allpeopletextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(agetextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_8)
.addComponent(mantextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_4)
.addComponent(zztextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(27)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_5)
.addComponent(zctextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(womentextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_9))))
.addGroup(groupLayout.createSequentialGroup()
.addGap(94)
.addComponent(btnNewButton_1)))
.addGap(105))
);
table = new JTable();
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
rest(e);
}
});
table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"\u5B66\u5DE5\u53F7", "\u59D3\u540D", "\u6027\u522B", "\u5E74\u9F84", "\u653F\u6CBB\u9762\u8C8C", "\u804C\u79F0", "\u5BC6\u7801"
}
) {
boolean[] columnEditables = new boolean[] {
false, false, false, false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
scrollPane.setViewportView(table);
getContentPane().setLayout(groupLayout);
Administrative cs=new Administrative();
setTable(new Administrative());
AdministrativeDao sc1=new AdministrativeDao();
allpeopletextField.setText(sc1.alltongji(new Administrative()));
mantextField.setText(sc1.tongji2(new Administrative()));
womentextField.setText(sc1.tongji(new Administrative()));
}
protected void delete(ActionEvent e) {
// TODO Auto-generated method stub
if(JOptionPane.showConfirmDialog(this, "您确定要删除吗?")!=JOptionPane.OK_OPTION) {
return;
}
int n=table.getSelectedRow();
if(n==-1) {
JOptionPane.showMessageDialog(this, "请选择要删除的数据!");
return;
}
DefaultTableModel dfDefaultTableModel=(DefaultTableModel) table.getModel();
String idString=(String) (dfDefaultTableModel.getValueAt(table.getSelectedRow(), 0).toString());
AdministrativeDao cs=new AdministrativeDao();
JOptionPane.showMessageDialog(this, cs.delete(idString));
setTable(new Administrative());
}
protected void editact(ActionEvent e) {
// TODO Auto-generated method stub
int n=table.getSelectedRow();
if(n==-1) {
JOptionPane.showMessageDialog(this, "请选择要修改的数据!");
return;
}
DefaultTableModel dfDefaultTableModel=(DefaultTableModel) table.getModel();
String id=dfDefaultTableModel.getValueAt(table.getSelectedRow(),0).toString();
String name=dfDefaultTableModel.getValueAt(table.getSelectedRow(), 1).toString();
String sex=dfDefaultTableModel.getValueAt(table.getSelectedRow(), 2).toString();
String age=dfDefaultTableModel.getValueAt(table.getSelectedRow(), 3).toString();
String zz=dfDefaultTableModel.getValueAt(table.getSelectedRow(), 4).toString();
String zc=dfDefaultTableModel.getValueAt(table.getSelectedRow(), 5).toString();
//String password=dfDefaultTableModel.getValueAt(table.getSelectedRow(), 7).toString();
String editname=nametextField.getText().toString();
String editsex=sextextField.getText().toString();
String editage=agetextField.getText().toString();
String editzz=zztextField.getText().toString();
String editzc=zctextField.getText().toString();
if(StringUtil.isEmpty(editname)||StringUtil.isEmpty(editsex)||StringUtil.isEmpty(editage)||StringUtil.isEmpty(editzz)||StringUtil.isEmpty(editzc)) {
JOptionPane.showMessageDialog(this, "您还有信息尚未填写完整!");
return;
}
if(name.equals(editname)&&age.equals(editage)&&sex.equals(editsex)&&zz.equals(editzz)&&zc.equals(zc)) {
JOptionPane.showMessageDialog(this, "您还没有做出任何修改!");
return;
}
else {
Administrative sc=new Administrative();
sc.setId(id);
sc.setName(editname);
sc.setSex(editsex);
sc.setAge(editage);
sc.setZz(editzz);
sc.setZc(editzc);
//sc.setPassword(editpassword);
AdministrativeDao cs=new AdministrativeDao();
JOptionPane.showMessageDialog(this, cs.reststu(sc));
setTable(new Administrative());
}
}
protected void rest(MouseEvent e) {
// TODO Auto-generated method stub
DefaultTableModel dfDefaultTableModel=(DefaultTableModel) table.getModel();
//idtextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(),0).toString());
nametextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(), 1).toString());
sextextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(), 2).toString());
agetextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(), 3).toString());
zztextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(), 4).toString());
zctextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(), 5).toString());
//passwordtextField.setText(dfDefaultTableModel.getValueAt(table.getSelectedRow(), 7).toString());
}
private void setTable(Administrative classstudents1) {
// TODO Auto-generated method stub
DefaultTableModel dft=(DefaultTableModel) table.getModel();
dft.setRowCount(0);
AdministrativeDao cs=new AdministrativeDao();
List<Administrative> classList=cs.getClassList(classstudents1);
for(Administrative cst:classList) {
Vector vector=new Vector();
vector.add(cst.getId());
vector.add(cst.getName());
vector.add(cst.getSex());
vector.add(cst.getAge());
vector.add(cst.getZz());
vector.add(cst.getZc());
vector.add(cst.getPassword());
dft.addRow(vector);
}
}
}
运行效果:文章来源:https://www.toymoban.com/news/detail-494114.html
文章来源地址https://www.toymoban.com/news/detail-494114.html
到了这里,关于高校人员信息管理系统(Java课程设计,带图形界面版)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!