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

}

你可能感兴趣的:(java,设计)