Java设计模块系列之书店管理系统单机版(三)

介绍

今天对系列二的一个添加用户的输入小bug进行了解决, 增加了用户模块的,删除用户,和修改用户模块。

下面的代码是相对于系列二来说进行了修改或者是增加的类.

先看AddPanel类的修改:
在收集参数的时候进行防范就可防止那个bug了。

cn.hncu.bookStore.user.ui;

AddPanel类:(添加用户模块)

/*
 * AddPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.user.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.common.UserTypeEnum;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.util.FileIoUtil;

/**
 *
 * @author 陈浩翔
 */
public class AddPanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;

 /** Creates new form AddPanel */
 public AddPanel(JFrame mainFrame) {
  this.mainFrame = mainFrame;
  initComponents();
  myInitData();
 }

 private void myInitData() {
  for (UserTypeEnum type : UserTypeEnum.values()) {
   combType.addItem(type.getName());
  }
 }

 /** This method is called from within the constructor to
  * initialize the form.
  * WARNING: Do NOT modify this code. The content of this method is
  * always regenerated by the Form Editor.
  */
 //GEN-BEGIN:initComponents
 // <editor-fold defaultstate="collapsed" desc="Generated Code">
 private void initComponents() {

  jLabel1 = new javax.swing.JLabel();
  jLabel2 = new javax.swing.JLabel();
  tfdName = new javax.swing.JTextField();
  jLabel3 = new javax.swing.JLabel();
  tfdUuid = new javax.swing.JTextField();
  jLabel4 = new javax.swing.JLabel();
  tfdPwd2 = new javax.swing.JPasswordField();
  jLabel5 = new javax.swing.JLabel();
  jLabel6 = new javax.swing.JLabel();
  combType = new javax.swing.JComboBox();
  tfdPwd = new javax.swing.JPasswordField();
  btnAdd = new javax.swing.JButton();
  btnBack = new javax.swing.JButton();

  setMinimumSize(new java.awt.Dimension(800, 600));
  setLayout(null);

  jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
  jLabel1.setForeground(new java.awt.Color(204, 0, 0));
  jLabel1.setText("\u6dfb\u52a0\u7528\u6237");
  add(jLabel1);
  jLabel1.setBounds(330, 30, 230, 80);

  jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(90, 310, 90, 30);

  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(470, 160, 120, 30);

  jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel3.setText("uuid:");
  add(jLabel3);
  jLabel3.setBounds(120, 160, 50, 30);

  tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
  add(tfdUuid);
  tfdUuid.setBounds(190, 160, 110, 30);

  jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(410, 160, 50, 30);

  tfdPwd2.setFont(new java.awt.Font("宋体", 1, 18));
  add(tfdPwd2);
  tfdPwd2.setBounds(470, 240, 170, 30);

  jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(120, 240, 50, 30);

  jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel6.setText("\u786e\u8ba4\u5bc6\u7801:");
  add(jLabel6);
  jLabel6.setBounds(380, 240, 90, 30);

  combType.setFont(new java.awt.Font("Dialog", 1, 18));
  combType.setForeground(new java.awt.Color(51, 51, 255));
  combType.setModel(new javax.swing.DefaultComboBoxModel(
    new String[] { "请选择..." }));
  add(combType);
  combType.setBounds(190, 310, 160, 30);

  tfdPwd.setFont(new java.awt.Font("宋体", 1, 18));
  add(tfdPwd);
  tfdPwd.setBounds(190, 240, 160, 30);

  btnAdd.setFont(new java.awt.Font("Dialog", 1, 24));
  btnAdd.setForeground(new java.awt.Color(0, 204, 204));
  btnAdd.setText("\u6dfb\u52a0");
  btnAdd.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnAddActionPerformed(evt);
   }
  });
  add(btnAdd);
  btnAdd.setBounds(190, 430, 120, 60);

  btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
  btnBack.setForeground(new java.awt.Color(0, 204, 204));
  btnBack.setText("\u8fd4\u56de");
  btnBack.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnBackActionPerformed(evt);
   }
  });
  add(btnBack);
  btnBack.setBounds(520, 430, 120, 60);
 }// </editor-fold>
 //GEN-END:initComponents

 private void back() {
  mainFrame.setContentPane(new ListPanel(mainFrame));
  mainFrame.validate();
 }

 /**
  *监听返回按钮
  * @param 返回按钮的点击监听
  */
 private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  back();
 }

 private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
  //1收集参数
  String uuid = tfdUuid.getText();
  String name = tfdName.getText();
  String pwd = new String(tfdPwd.getPassword());
  String pwd2 = new String(tfdPwd2.getPassword());
  //System.out.println(uuid);

  //System.out.println(uuid+","+name+","+pwd);
  if (uuid.equals("") || uuid.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户ID为空,请重新输入!");
   return;
  }

  if (name.equals("") || name.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户名为空,请重新输入!");
   return;
  }

  if (!pwd.equals(pwd2) || pwd.equals("") || pwd.equals(null)
    || pwd2.equals("") || pwd2.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "两次密码输入不一致或密码为空,请重新输入!");
   return;
  }
  int type = 0;

  try {
   type = UserTypeEnum.getTypeByName(combType.getSelectedItem()
     .toString());
  } catch (Exception e) {
   JOptionPane.showMessageDialog(mainFrame, "请指定用户类型!");
   return;
  }

  //2组织参数
  UserModel user = new UserModel();
  user.setName(name);
  user.setPwd(pwd);
  user.setType(type);
  user.setUuid(uuid);

  //3调用逻辑层
  UserEbi ebi = UserEbiFactory.getUserEbi();

  //4根据调用返回结果导向不同页面
  if (ebi.create(user)) {
   back();
  } else {
   JOptionPane.showMessageDialog(null, "该用户已经存在!");
  }
 }

 //GEN-BEGIN:variables
 // Variables declaration - do not modify
 private javax.swing.JButton btnAdd;
 private javax.swing.JButton btnBack;
 private javax.swing.JComboBox combType;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JTextField tfdName;
 private javax.swing.JPasswordField tfdPwd;
 private javax.swing.JPasswordField tfdPwd2;
 private javax.swing.JTextField tfdUuid;
 // End of variables declaration//GEN-END:variables

}

cn.hncu.bookStore.user.ui;

DeletePanel类:(删除用户模块)

/*
 * DeletePanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.user.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.common.UserTypeEnum;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.util.FileIoUtil;

/**
 *
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class DeletePanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;
 private String uuid = null;

 /** Creates new form DeletePanel
  * @param uuid */
 public DeletePanel(JFrame mainFrame, String uuid) {
  this.mainFrame = mainFrame;
  this.uuid = uuid;
  initComponents();
  myInitData();
 }

 private void myInitData() {
  UserEbi user = UserEbiFactory.getUserEbi();
  UserModel userModel = user.getSingle(uuid);
  tfdName.setText(userModel.getName());
  tfdUuid.setText(userModel.getUuid());
  tfdPwd.setText(userModel.getPwd());
  tfdType.setText(UserTypeEnum.getNameByType(userModel.getType()));

  tfdName.setEditable(false);
  tfdPwd.setEditable(false);
  tfdType.setEditable(false);
  tfdUuid.setEditable(false);

 }

 //GEN-BEGIN:initComponents
 // <editor-fold defaultstate="collapsed" desc="Generated Code">
 private void initComponents() {

  jLabel1 = new javax.swing.JLabel();
  jLabel2 = new javax.swing.JLabel();
  tfdName = new javax.swing.JTextField();
  jLabel3 = new javax.swing.JLabel();
  tfdUuid = new javax.swing.JTextField();
  jLabel4 = new javax.swing.JLabel();
  jLabel5 = new javax.swing.JLabel();
  tfdPwd = new javax.swing.JTextField();
  tfdType = new javax.swing.JTextField();
  btnBack = new javax.swing.JButton();
  btnDelete = new javax.swing.JButton();

  setMinimumSize(new java.awt.Dimension(800, 600));
  setLayout(null);

  jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
  jLabel1.setForeground(new java.awt.Color(204, 0, 0));
  jLabel1.setText("\u5220\u9664\u7528\u6237");
  add(jLabel1);
  jLabel1.setBounds(330, 30, 230, 80);

  jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(100, 310, 90, 30);

  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(480, 160, 120, 30);

  jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel3.setText("uuid:");
  add(jLabel3);
  jLabel3.setBounds(130, 160, 50, 30);

  tfdUuid.setFont(new java.awt.Font("Dialog", 0, 11));
  add(tfdUuid);
  tfdUuid.setBounds(200, 160, 110, 30);

  jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(420, 160, 50, 30);

  jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(130, 240, 50, 30);

  tfdPwd.setFont(new java.awt.Font("Tahoma", 1, 12));
  add(tfdPwd);
  tfdPwd.setBounds(200, 240, 160, 30);

  tfdType.setFont(new java.awt.Font("Dialog", 1, 12));
  add(tfdType);
  tfdType.setBounds(200, 310, 160, 30);

  btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
  btnBack.setForeground(new java.awt.Color(0, 204, 204));
  btnBack.setText("\u8fd4\u56de");
  btnBack.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnBackActionPerformed(evt);
   }
  });
  add(btnBack);
  btnBack.setBounds(540, 450, 120, 60);

  btnDelete.setFont(new java.awt.Font("Dialog", 1, 24));
  btnDelete.setForeground(new java.awt.Color(0, 204, 204));
  btnDelete.setText("\u5220\u9664");
  btnDelete.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnDeleteActionPerformed(evt);
   }
  });
  add(btnDelete);
  btnDelete.setBounds(210, 450, 120, 60);
 }// </editor-fold>
 //GEN-END:initComponents

 private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
  //3调用逻辑层
  if (UserEbiFactory.getUserEbi().delete(uuid)) {
   back();
  } else {
   JOptionPane.showMessageDialog(mainFrame, "该用户已经不存在!");
  }

  //4根据调用返回结果导向不同页面

 }

 private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  back();
 }

 private void back() {
  mainFrame.setContentPane(new ListPanel(mainFrame));
  mainFrame.validate();
 }

 //GEN-BEGIN:variables
 // Variables declaration - do not modify
 private javax.swing.JButton btnBack;
 private javax.swing.JButton btnDelete;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JTextField tfdName;
 private javax.swing.JTextField tfdPwd;
 private javax.swing.JTextField tfdType;
 private javax.swing.JTextField tfdUuid;
 // End of variables declaration//GEN-END:variables

}

cn.hncu.bookStore.user.ui;

UpdatePanel类:(修改用户模块)

/*
 * UpdatePanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.user.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.common.UserTypeEnum;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;

/**
 *
 * @author 陈浩翔
 *
 * @version 1.0
 */
public class UpdatePanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;
 private String uuid = null;

 /**
  * Creates new form UpdatePanel
  *
  * @param uuid
  * @param mainFrame
  */
 public UpdatePanel(JFrame mainFrame, String uuid) {
  this.mainFrame = mainFrame;
  this.uuid = uuid;
  initComponents();
  myInitData();
 }

 private void myInitData() {
  UserEbi ebi = UserEbiFactory.getUserEbi();
  UserModel user = ebi.getSingle(uuid);
  tfdUuid.setText(user.getUuid());
  tfdUuid.setEditable(false);

  tfdName.setText(user.getName());
  tfdPwd.setText(user.getPwd());
  tfdPwd2.setText(user.getPwd());

  combType.removeAllItems();
  String usert = UserTypeEnum.getNameByType(user.getType());
  combType.addItem(usert);
  for (UserTypeEnum userType : UserTypeEnum.values()) {
   if (!userType.getName().equals(usert)) {
    combType.addItem(userType.getName());
   }
  }

 }

 // GEN-BEGIN:initComponents
 // <editor-fold defaultstate="collapsed" desc="Generated Code">
 private void initComponents() {

  jLabel1 = new javax.swing.JLabel();
  jLabel2 = new javax.swing.JLabel();
  tfdName = new javax.swing.JTextField();
  jLabel3 = new javax.swing.JLabel();
  tfdUuid = new javax.swing.JTextField();
  jLabel4 = new javax.swing.JLabel();
  tfdPwd2 = new javax.swing.JPasswordField();
  jLabel5 = new javax.swing.JLabel();
  jLabel6 = new javax.swing.JLabel();
  tfdPwd = new javax.swing.JPasswordField();
  combType = new javax.swing.JComboBox();
  btnBack = new javax.swing.JButton();
  btnUpdate = new javax.swing.JButton();

  setMinimumSize(new java.awt.Dimension(800, 600));
  setLayout(null);

  jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 48));
  jLabel1.setForeground(new java.awt.Color(204, 0, 0));
  jLabel1.setText("\u4fee\u6539\u7528\u6237");
  add(jLabel1);
  jLabel1.setBounds(320, 30, 230, 80);

  jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel2.setText("\u7528\u6237\u7c7b\u578b:");
  add(jLabel2);
  jLabel2.setBounds(90, 310, 90, 30);

  tfdName.setFont(new java.awt.Font("Dialog", 1, 18));
  tfdName.setAutoscrolls(false);
  add(tfdName);
  tfdName.setBounds(470, 160, 120, 30);

  jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel3.setText("uuid:");
  add(jLabel3);
  jLabel3.setBounds(120, 160, 50, 30);

  tfdUuid.setFont(new java.awt.Font("Dialog", 1, 12));
  add(tfdUuid);
  tfdUuid.setBounds(190, 160, 110, 30);

  jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel4.setText("\u59d3\u540d:");
  add(jLabel4);
  jLabel4.setBounds(410, 160, 50, 30);

  tfdPwd2.setFont(new java.awt.Font("Dialog", 1, 18));
  add(tfdPwd2);
  tfdPwd2.setBounds(470, 240, 170, 30);

  jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel5.setText("\u5bc6\u7801:");
  add(jLabel5);
  jLabel5.setBounds(120, 240, 50, 30);

  jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 18));
  jLabel6.setText("\u786e\u8ba4\u5bc6\u7801:");
  add(jLabel6);
  jLabel6.setBounds(380, 240, 90, 30);

  tfdPwd.setFont(new java.awt.Font("宋体", 1, 18));
  add(tfdPwd);
  tfdPwd.setBounds(190, 240, 160, 30);

  combType.setFont(new java.awt.Font("Dialog", 1, 12));
  combType.setForeground(new java.awt.Color(51, 0, 255));
  combType.setModel(new javax.swing.DefaultComboBoxModel(
    new String[] { "" }));
  add(combType);
  combType.setBounds(190, 310, 170, 30);

  btnBack.setFont(new java.awt.Font("Dialog", 1, 24));
  btnBack.setForeground(new java.awt.Color(0, 204, 204));
  btnBack.setText("\u8fd4\u56de");
  btnBack.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnBackActionPerformed(evt);
   }
  });
  add(btnBack);
  btnBack.setBounds(500, 430, 120, 60);

  btnUpdate.setFont(new java.awt.Font("Dialog", 1, 24));
  btnUpdate.setForeground(new java.awt.Color(0, 204, 204));
  btnUpdate.setText("\u4fee\u6539");
  btnUpdate.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnUpdateActionPerformed(evt);
   }
  });
  add(btnUpdate);
  btnUpdate.setBounds(170, 430, 120, 60);
 }// </editor-fold>
  // GEN-END:initComponents

 private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
  // 1收集参数
  String uuid = tfdUuid.getText();
  String name = tfdName.getText();
  String pwd = new String(tfdPwd.getPassword());
  String pwd2 = new String(tfdPwd2.getPassword());

  if (uuid.equals("") || uuid.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户ID为空,请重新输入!");
   return;
  }

  if (name.equals("") || name.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "用户名为空,请重新输入!");
   return;
  }

  if (!pwd.equals(pwd2) || pwd.equals("") || pwd.equals(null)
    || pwd2.equals("") || pwd2.equals(null)) {
   JOptionPane.showMessageDialog(mainFrame, "两次密码输入不一致或密码为空,请重新输入!");
   return;
  }
  int type = 0;

  try {
   type = UserTypeEnum.getTypeByName(combType.getSelectedItem()
     .toString());
  } catch (Exception e) {
   JOptionPane.showMessageDialog(mainFrame, "请指定用户类型!");
   return;
  }

  // 2组织参数
  UserModel user = new UserModel();
  user.setName(name);
  user.setPwd(pwd);
  user.setType(type);
  user.setUuid(uuid);

  // 3调用逻辑层
  UserEbi ebi = UserEbiFactory.getUserEbi();

  // 4根据调用返回结果导向不同页面
  if (ebi.update(user)) {
   back();
  } else {
   JOptionPane.showMessageDialog(null, "该用户已经不存在!");
  }

 }

 private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
  back();
 }

 private void back() {
  mainFrame.setContentPane(new ListPanel(mainFrame));
  mainFrame.validate();
 }

 // GEN-BEGIN:variables
 // Variables declaration - do not modify
 private javax.swing.JButton btnBack;
 private javax.swing.JButton btnUpdate;
 private javax.swing.JComboBox combType;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JTextField tfdName;
 private javax.swing.JPasswordField tfdPwd;
 private javax.swing.JPasswordField tfdPwd2;
 private javax.swing.JTextField tfdUuid;
 // End of variables declaration//GEN-END:variables

}

cn.hncu.bookStore.user.ui;

ListPanel类(调用用户功能模块)

/*
 * ListPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.bookStore.user.ui;

import java.util.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserModel;

/**
 * 表现层-用户列表面板
 *
 * @author 陈浩翔
 * @version 1.0
 */
public class ListPanel extends javax.swing.JPanel {
 private JFrame mainFrame = null;

 /** Creates new form ListPanel */
 public ListPanel(JFrame mainFrame) {
  this.mainFrame = mainFrame;
  initComponents();
  myInitData();
 }

 /**
  * 读取所有用户并添加进列表
  */
 private void myInitData() {
  UserEbi user = UserEbiFactory.getUserEbi();
  List<UserModel> list = user.getAll();
  userLists.setListData(list.toArray());
 }

 //GEN-BEGIN:initComponents
 // <editor-fold defaultstate="collapsed" desc="Generated Code">
 private void initComponents() {

  jScrollPane1 = new javax.swing.JScrollPane();
  userLists = new javax.swing.JList();
  jLabel1 = new javax.swing.JLabel();
  btnToAdd = new javax.swing.JButton();
  btnToDelete = new javax.swing.JButton();
  btnToUpdate = new javax.swing.JButton();

  setMinimumSize(new java.awt.Dimension(800, 600));
  setLayout(null);

  userLists.setModel(new javax.swing.AbstractListModel() {
   String[] strings = { "" };

   public int getSize() {
    return strings.length;
   }

   public Object getElementAt(int i) {
    return strings[i];
   }
  });
  jScrollPane1.setViewportView(userLists);

  add(jScrollPane1);
  jScrollPane1.setBounds(170, 80, 480, 230);

  jLabel1.setFont(new java.awt.Font("Tahoma", 1, 48));
  jLabel1.setForeground(new java.awt.Color(204, 0, 51));
  jLabel1.setText("User List");
  add(jLabel1);
  jLabel1.setBounds(300, 0, 260, 80);

  btnToAdd.setFont(new java.awt.Font("Dialog", 1, 24));
  btnToAdd.setForeground(new java.awt.Color(0, 102, 102));
  btnToAdd.setText("\u6dfb\u52a0\u7528\u6237");
  btnToAdd.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnToAddActionPerformed(evt);
   }
  });
  add(btnToAdd);
  btnToAdd.setBounds(160, 350, 150, 50);

  btnToDelete.setFont(new java.awt.Font("Dialog", 1, 24));
  btnToDelete.setForeground(new java.awt.Color(0, 102, 102));
  btnToDelete.setText("\u5220\u9664\u7528\u6237");
  btnToDelete.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnToDeleteActionPerformed(evt);
   }
  });
  add(btnToDelete);
  btnToDelete.setBounds(510, 350, 150, 50);

  btnToUpdate.setFont(new java.awt.Font("Dialog", 1, 24));
  btnToUpdate.setForeground(new java.awt.Color(0, 102, 102));
  btnToUpdate.setText("\u4fee\u6539\u7528\u6237");
  btnToUpdate.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnToUpdateActionPerformed(evt);
   }
  });
  add(btnToUpdate);
  btnToUpdate.setBounds(160, 450, 150, 50);
 }// </editor-fold>
 //GEN-END:initComponents

 private void btnToUpdateActionPerformed(java.awt.event.ActionEvent evt) {
  UserModel user = (UserModel) userLists.getSelectedValue();

  if (user == null) {
   JOptionPane.showMessageDialog(mainFrame, "请选择要修改的用户!");
   return;
  }

  String uuid = user.getUuid();

  mainFrame.setContentPane(new UpdatePanel(mainFrame, uuid));
  mainFrame.validate();
 }

 private void btnToDeleteActionPerformed(java.awt.event.ActionEvent evt) {
  UserModel user = (UserModel) userLists.getSelectedValue();

  if (user == null) {
   JOptionPane.showMessageDialog(mainFrame, "请选择要删除的用户!");
   return;
  }

  String uuid = user.getUuid();

  mainFrame.setContentPane(new DeletePanel(mainFrame, uuid));
  mainFrame.validate();
 }

 private void btnToAddActionPerformed(java.awt.event.ActionEvent evt) {
  mainFrame.setContentPane(new AddPanel(mainFrame));
  mainFrame.validate();
 }

 //GEN-BEGIN:variables
 // Variables declaration - do not modify
 private javax.swing.JButton btnToAdd;
 private javax.swing.JButton btnToDelete;
 private javax.swing.JButton btnToUpdate;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JScrollPane jScrollPane1;
 private javax.swing.JList userLists;
 // End of variables declaration//GEN-END:variables

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • C++实现简单的职工管理系统实训代码

    本文实例为大家分享了C++职工管理系统实例代码 1.单个职工的头文件 staff.h #ifndef STAFF_H_INCLUDED #define STAFF_H_INCLUDED //结构体创建 struct staff { char ID[10]; char name[10]; char sex[10]; int pay; int reward; int factpay; }; //自定义结构体 typedef struct staff staff; //单个职工信息创建 staff C

  • java开发就业信息管理系统

    本文实例为大家分享了java就业信息管理平台开发案例,供大家参考,具体内容如下 可查询公司信息,学生信息,班级信息,针对学生就业与否信息的统计,老师和管理员登录后的权限不同等 就业信息管理平台想要实现的是各个班级的学生就业情况,数据库里建有6张表,分别是班级,公司,职位,学生,登录用户. 其中就业信息在界面上显示的内容是学生信息和职位的组合,在jsp页面中是拼接来实现,如果这个学生找到工作则需要填写就业信息,否则空着.如就业截图. 在企业信息中,需要实现的功能是首先有计划招聘时间,实际招聘时间,

  • Winform学生信息管理系统登陆窗体设计(1)

    对这块的知识学习早已期待已久,感觉学习的进度还是慢了,最近一直在学习Winform,不得不说一些登陆窗体的设计,这几天算是小有收获,自己也看了许多这方面的知识,知道了要想做学生信息管理系统是一个漫长的过程,但是从今天起就来慢慢地进行学生信息管理系统的构建,此外还用到数据库的知识,打算着自己开始学数据库的知识,今天就来看看学生信息管理系统登录窗口的设计.下面图片的是样例: 这方面的知识还是基于C#语言和.NET Framework平台的.自己所用的还是熟悉的开发环境VS2012,感觉VS2013和

  • C++学生信息管理系统

    本文实例为大家分享了C++学生信息管理系统源码,供大家参考,具体内容如下 1. tea_list.c #include<stdio.h> #include<stdlib.h> #include<string.h> #include"teacher.h" int sq_tea ; PTEA head = NULL ; FILE *fp ; int tea_llopen(const char* path)//打开文件 { fp=fopen(path,&q

  • ASP.NET实现学生管理系统

    学生管理系统所需要的具体控件和主要属性: 1.登录窗体 基本控件: label(标签控件) 主要属性:Image(在标签上显示的图像) Text(在标签上显示的文本) TextBox(文本框控件) 主要属性:PasswordChar(指示在作为密码框时,文本框中显示的字符,而不是实际输入的文本) Button(按钮控件) ComboBox(下拉框)属性:SelectedItem:获取当前选定的项 事件:Click(单击控件时发生) private void butStyle_Click(obje

  • Java+Mysql学生管理系统源码

    最近正在学java和数据库,想起以前写的学生管理系统,都是从网上下载,敷衍了事.闲来无事,也就自己写了一个,不过功能实现的不是很多. 开发语言:java: 开发环境:Mysql, java: 开发工具:eclipse 开发此案例,首先得在电脑上有java开发环境和Mysql, java开发环境与Mysql的搭建,就不再叙述了,如果需要,请联系我最下面的联系方式:dingyelf@aliyun.com 此次系统比较简易:数据库中只有一个表:stu;功能:能够对学生增加.删除.修改. 开发步骤:  

  • JavaEE在线人数管理系统

    这篇博客是filter.listener和servlet技术的相关总结,实现了简单的显示在线人数.在线人详细信息.管理员踢人功能 下面是详细代码 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http:

  • Android实现学生管理系统

    本文实例为大家分享了Android实现学生管理系统的关键性代码,供大家参考,具体内容如下 局部效果图: 实现代码: 1.布局 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima27.sutdentmanager&qu

  • C++实现简单的信息管理系统

    本文为大家分享C++实现简单的信息管理系统,小编之前在学习的时候也要做一些管理系统,在网上查了许多资料,现在我把资料分享给大家,希望能够帮助到大家. #include <stdio.h> #include <stdlib.h> #include "file.h" void savaList(Node *head)/**把用户录入的数据存储到文件里面去方便下次读取*/ { FILE *fp=fopen("data\\data.txt" ,&qu

  • 简单实现Java版学生管理系统

    本文实例为大家分享了Java实现学生管理系统的具体代码,供大家参考,具体内容如下 package BookDemo_1; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Test { public static void main(String[] args) { StudentSys stuSys=new StudentSys("学生管理系统"); stuSys.initWi

随机推荐