关闭

书店管理系统---User模块.表现层(JavaSE综合运用(三))

459人阅读 评论(0) 收藏 举报
分类:

表现层就是采用VE设计 界面 具体的界面切换是通过构造传参实现
listPanel
这里写图片描述 AddPanelAddPanel DeletePanel UpdatePanel QueryPanel

用户信息界面代码

/*
 * 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.dao.dao.Userdao;
import cn.hncu.bookStore.user.vo.UserQueryVO;
import cn.hncu.bookStore.user.vo.UserVO;

/**
 *
 * @author  __USER__
 */
public class ListPanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;
    //注入Dao
    private UserEbi ebi = UserEbiFactory.getUserEbi();

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

    public ListPanel(JFrame mainFrame, List<UserVO> res) {
        this.mainFrame = mainFrame;
        initComponents();

        jList1.setListData(res.toArray());

    }

    private void myInitComponents() {
        List<UserVO> list = ebi.getAll();
        jList1.setListData(list.toArray());

    }

    /** 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();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        btnTOadd = new javax.swing.JButton();
        btnTOdel = new javax.swing.JButton();
        btnTOupdate = new javax.swing.JButton();
        btnTOquery = new javax.swing.JButton();

        setBackground(new java.awt.Color(204, 255, 153));
        setMinimumSize(new java.awt.Dimension(800, 500));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("黑体", 0, 36));
        jLabel1.setText("\u7528\u6237\u4fe1\u606f\u7ba1\u7406");
        add(jLabel1);
        jLabel1.setBounds(170, 40, 240, 70);

        jList1.setBackground(new java.awt.Color(153, 255, 153));
        jList1.setFont(new java.awt.Font("黑体", 1, 24));
        jList1.setForeground(new java.awt.Color(51, 0, 204));
        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "" };

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

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

        add(jScrollPane1);
        jScrollPane1.setBounds(60, 140, 440, 270);

        btnTOadd.setFont(new java.awt.Font("黑体", 0, 24));
        btnTOadd.setText("\u589e\u52a0");
        btnTOadd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTOaddActionPerformed(evt);
            }
        });
        add(btnTOadd);
        btnTOadd.setBounds(580, 140, 130, 40);

        btnTOdel.setFont(new java.awt.Font("黑体", 0, 24));
        btnTOdel.setText("\u5220\u9664");
        btnTOdel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTOdelActionPerformed(evt);
            }
        });
        add(btnTOdel);
        btnTOdel.setBounds(580, 220, 130, 40);

        btnTOupdate.setFont(new java.awt.Font("黑体", 0, 24));
        btnTOupdate.setText("\u4fee\u6539");
        btnTOupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTOupdateActionPerformed(evt);
            }
        });
        add(btnTOupdate);
        btnTOupdate.setBounds(580, 300, 130, 40);

        btnTOquery.setFont(new java.awt.Font("黑体", 0, 24));
        btnTOquery.setText("\u67e5\u8be2");
        btnTOquery.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTOqueryActionPerformed(evt);
            }
        });
        add(btnTOquery);
        btnTOquery.setBounds(580, 380, 130, 40);
    }// </editor-fold>
    //GEN-END:initComponents

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

    private void btnTOupdateActionPerformed(java.awt.event.ActionEvent evt) {
        if (jList1.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "请选择要修改项");
            return;
        }
        UserVO vo = (UserVO) jList1.getSelectedValue();
        String uuid = vo.getUuid();

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

    //GEN-END:initComponents

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

    private void btnTOdelActionPerformed(java.awt.event.ActionEvent evt) {
        if (jList1.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "请选择要删除项");
            return;
        }
        UserVO vo = (UserVO) jList1.getSelectedValue();
        String uuid = vo.getUuid();
        mainFrame.setContentPane(new DeletePanel(mainFrame, uuid));
        mainFrame.validate();
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton btnTOadd;
    private javax.swing.JButton btnTOdel;
    private javax.swing.JButton btnTOquery;
    private javax.swing.JButton btnTOupdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}

添加用户界面代码

/*
 * 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.dao.dao.Userdao;
import cn.hncu.bookStore.user.dao.factory.UserDaoFactory;
import cn.hncu.bookStore.user.vo.UserVO;

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

    //注入逻辑层
    private UserEbi ebi = null;

    /** Creates new form AddPanel 
     * @param mainFram */
    public AddPanel(JFrame mainFrame) {
        this.mainFrame = mainFrame;
        initComponents();
        myInitComponents();
    }

    private void myInitComponents() {
        for (UserTypeEnum userType : UserTypeEnum.values()) {
            ComboBoxType.addItem(userType.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();
        btnAdd = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        tfduuid = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfdName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        ComboBoxType = new javax.swing.JComboBox();
        tfdPwd2 = new javax.swing.JPasswordField();
        tfdPwd1 = new javax.swing.JPasswordField();

        setBackground(new java.awt.Color(204, 255, 102));
        setMinimumSize(new java.awt.Dimension(800, 500));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("黑体", 0, 36));
        jLabel1.setText("\u6dfb\u52a0\u7528\u6237\u4fe1\u606f");
        add(jLabel1);
        jLabel1.setBounds(280, 30, 240, 70);

        btnAdd.setFont(new java.awt.Font("黑体", 0, 24));
        btnAdd.setText("\u589e\u52a0");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        add(btnAdd);
        btnAdd.setBounds(550, 360, 130, 40);

        jLabel2.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel2.setText("\u7f16\u53f7\uff1a");
        add(jLabel2);
        jLabel2.setBounds(130, 150, 90, 50);

        tfduuid.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfduuid);
        tfduuid.setBounds(220, 150, 170, 50);

        jLabel3.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel3.setText("\u59d3\u540d\uff1a");
        add(jLabel3);
        jLabel3.setBounds(430, 150, 90, 50);

        tfdName.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfdName);
        tfdName.setBounds(520, 150, 170, 50);

        jLabel4.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel4.setText("\u7528\u6237\u7c7b\u578b\uff1a");
        add(jLabel4);
        jLabel4.setBounds(90, 300, 130, 50);

        jLabel5.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel5.setText("\u786e\u8ba4\u5bc6\u7801\uff1a");
        add(jLabel5);
        jLabel5.setBounds(400, 220, 130, 50);

        jLabel6.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel6.setText("\u5bc6\u7801\uff1a");
        add(jLabel6);
        jLabel6.setBounds(130, 220, 90, 50);

        jButton3.setFont(new java.awt.Font("黑体", 0, 24));
        jButton3.setText("\u8fd4\u56de");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        add(jButton3);
        jButton3.setBounds(550, 440, 130, 40);

        ComboBoxType.setFont(new java.awt.Font("黑体", 0, 24));
        ComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "选择用户类型" }));
        add(ComboBoxType);
        ComboBoxType.setBounds(220, 300, 170, 40);

        tfdPwd2.setFont(new java.awt.Font("黑体", 0, 12));
        add(tfdPwd2);
        tfdPwd2.setBounds(520, 220, 170, 50);

        tfdPwd1.setFont(new java.awt.Font("黑体", 0, 12));
        add(tfdPwd1);
        tfdPwd1.setBounds(220, 220, 170, 50);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
        //表现层框架
        //1:收集参数
        String uuid = tfduuid.getText();
        String name = tfdName.getText();
        String pwd1 = tfdPwd1.getText();
        String pwd2 = tfdPwd2.getText();
        int type = UserTypeEnum.getTypeByName((String) ComboBoxType
                .getSelectedItem());
        if (!pwd1.equals(pwd2)) { // 两次密码不一致
            JOptionPane.showMessageDialog(null, "两次密码不一致");
            return;
        }
        //2:组织参数
        UserVO vo = new UserVO();
        vo.setName(name);
        vo.setType(type);
        vo.setUuid(uuid);
        vo.setPwd(pwd1);

        //3:调用逻辑层
        ebi = UserEbiFactory.getUserEbi();
        boolean boo = ebi.create(vo);
        //4:根据逻辑层结果调不同界面
        if (boo) {
            back();
        } else {
            JOptionPane.showMessageDialog(null, "添加用户失败");
            return;
        }
    }

    private void jButton3ActionPerformed(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.JComboBox ComboBoxType;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton jButton3;
    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 tfdPwd1;
    private javax.swing.JPasswordField tfdPwd2;
    private javax.swing.JTextField tfduuid;
    // End of variables declaration//GEN-END:variables

}

删除界面代码

/*
 * DeletePanel.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.common.UserTypeEnum;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserVO;

/**
 *
 * @author  __USER__
 */
public class DeletePanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;
    private String uuid = null;
    //注入ebi
    private UserEbi ebi = null;

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

    private void myDataInitComponents() {
        ebi = UserEbiFactory.getUserEbi();
        List<UserVO> list = ebi.getAll();
        for (UserVO vo : list) {
            if (vo.getUuid().equals(uuid)) {
                tfdName.setText(vo.getName());
                tfdtype.setText(UserTypeEnum.getNameByType(vo.getType()));
                tfduuid.setText(uuid);
                return;

            }
        }
    }

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

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tfduuid = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        btdTodel = new javax.swing.JButton();
        btnback = new javax.swing.JButton();
        tfdtype = new javax.swing.JTextField();
        tfdName = new javax.swing.JTextField();

        setDoubleBuffered(false);
        setBackground(new java.awt.Color(204, 255, 153));
        setMinimumSize(new java.awt.Dimension(800, 500));
        setLayout(null);

        jLabel2.setFont(new java.awt.Font("黑体", 0, 36));
        jLabel2.setText("\u5220\u9664\u7528\u6237");
        add(jLabel2);
        jLabel2.setBounds(330, 40, 160, 70);

        jLabel3.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel3.setText("\u7f16\u53f7\uff1a");
        add(jLabel3);
        jLabel3.setBounds(130, 150, 90, 50);

        jLabel4.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel4.setText("\u59d3\u540d\uff1a");
        add(jLabel4);
        jLabel4.setBounds(430, 150, 90, 50);

        tfduuid.setFont(new java.awt.Font("黑体", 0, 24));
        tfduuid.setForeground(new java.awt.Color(204, 204, 204));
        tfduuid.setEnabled(false);
        add(tfduuid);
        tfduuid.setBounds(200, 150, 170, 50);

        jLabel6.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel6.setText("\u7c7b\u578b");
        add(jLabel6);
        jLabel6.setBounds(130, 270, 90, 50);

        btdTodel.setFont(new java.awt.Font("黑体", 0, 24));
        btdTodel.setText("\u5220\u9664");
        btdTodel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btdTodelActionPerformed(evt);
            }
        });
        add(btdTodel);
        btdTodel.setBounds(550, 360, 130, 40);

        btnback.setFont(new java.awt.Font("黑体", 0, 24));
        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(550, 440, 130, 40);

        tfdtype.setFont(new java.awt.Font("黑体", 0, 24));
        tfdtype.setForeground(new java.awt.Color(204, 204, 204));
        tfdtype.setEnabled(false);
        add(tfdtype);
        tfdtype.setBounds(200, 270, 170, 50);

        tfdName.setFont(new java.awt.Font("黑体", 0, 24));
        tfdName.setForeground(new java.awt.Color(204, 204, 204));
        tfdName.setEnabled(false);
        add(tfdName);
        tfdName.setBounds(520, 150, 170, 50);
    }// </editor-fold>
    //GEN-END:initComponents

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

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

    }

    private void btdTodelActionPerformed(java.awt.event.ActionEvent evt) {
        //表现层框架
        //1:收集参数
        //2:组织参数
        //3:调用逻辑层
        ebi=UserEbiFactory.getUserEbi();
        boolean boo= ebi.delete(uuid);
        //4:导向不同界面
        if(boo){
            back();
            return;
        }else{
            JOptionPane.showMessageDialog(this, "删除失败");
        }
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton btdTodel;
    private javax.swing.JButton btnback;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField tfdName;
    private javax.swing.JTextField tfdtype;
    private javax.swing.JTextField tfduuid;
    // End of variables declaration//GEN-END:variables

}

修改页面代码

/*
 * UpdatePanel.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.common.UserTypeEnum;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.factory.UserEbiFactory;
import cn.hncu.bookStore.user.vo.UserVO;

/**
 *
 * @author  __USER__
 */
public class UpdatePanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;
    private String uuid = null;
    private UserEbi ebi = null;
    private UserVO vo = null;

    /** Creates new form UpdatePanel 
     * @param mainFrame */
    public UpdatePanel(JFrame mainFrame, UserVO vo) {
        this.mainFrame = mainFrame;
        this.uuid = vo.getUuid();
        this.vo = vo;
        initComponents();
        myDataInitComponents();
    }

    private void myDataInitComponents() {
        ebi = UserEbiFactory.getUserEbi();
        List<UserVO> list = ebi.getAll();
        for (UserVO vo : list) {
            if (vo.getUuid().equals(uuid)) {
                tfdName.setText(vo.getName());
                tfduuid.setText(uuid);
                tfdpwd1.setText(vo.getPwd());
                tfdpwd2.setText(vo.getPwd());
                for (UserTypeEnum ute : UserTypeEnum.values()) {
                    ComboBoxType.addItem(ute.getName());
                }
                return;

            }
        }
    }

    /** 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();
        btnUpdate = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        tfduuid = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfdName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfdpwd1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfdpwd2 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        btnBack = new javax.swing.JButton();
        ComboBoxType = new javax.swing.JComboBox();

        setBackground(new java.awt.Color(204, 255, 153));
        setMinimumSize(new java.awt.Dimension(800, 500));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("黑体", 0, 36));
        jLabel1.setText("\u4fee\u6539\u7528\u6237\u4fe1\u606f");
        add(jLabel1);
        jLabel1.setBounds(280, 30, 240, 70);

        btnUpdate.setFont(new java.awt.Font("黑体", 0, 24));
        btnUpdate.setText("\u786e\u5b9a");
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });
        add(btnUpdate);
        btnUpdate.setBounds(550, 360, 130, 40);

        jLabel2.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel2.setText("\u7f16\u53f7\uff1a");
        add(jLabel2);
        jLabel2.setBounds(130, 150, 90, 50);

        tfduuid.setFont(new java.awt.Font("黑体", 0, 24));
        tfduuid.setForeground(new java.awt.Color(204, 204, 204));
        tfduuid.setEnabled(false);
        add(tfduuid);
        tfduuid.setBounds(220, 150, 170, 50);

        jLabel3.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel3.setText("\u59d3\u540d\uff1a");
        add(jLabel3);
        jLabel3.setBounds(430, 150, 90, 50);

        tfdName.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfdName);
        tfdName.setBounds(520, 150, 170, 50);

        jLabel4.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel4.setText("\u7528\u6237\u7c7b\u578b\uff1a");
        add(jLabel4);
        jLabel4.setBounds(100, 310, 130, 50);

        tfdpwd1.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfdpwd1);
        tfdpwd1.setBounds(220, 220, 170, 50);

        jLabel5.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel5.setText("\u786e\u8ba4\u5bc6\u7801\uff1a");
        add(jLabel5);
        jLabel5.setBounds(400, 220, 130, 50);

        tfdpwd2.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfdpwd2);
        tfdpwd2.setBounds(520, 220, 170, 50);

        jLabel6.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel6.setText("\u5bc6\u7801\uff1a");
        add(jLabel6);
        jLabel6.setBounds(130, 220, 90, 50);

        btnBack.setFont(new java.awt.Font("黑体", 0, 24));
        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(550, 440, 130, 40);

        ComboBoxType.setFont(new java.awt.Font("黑体", 0, 24));
        ComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "选择用户类型" }));
        add(ComboBoxType);
        ComboBoxType.setBounds(220, 320, 170, 40);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
        //表现层框架
                //1:收集参数
                String uuid = tfduuid.getText();
                String name = tfdName.getText();
                String pwd1 = tfdpwd1.getText();
                String pwd2 = tfdpwd2.getText();
                int type = UserTypeEnum.getTypeByName((String) ComboBoxType
                        .getSelectedItem());
                if (!pwd1.equals(pwd2)) { // 两次密码不一致
                    JOptionPane.showMessageDialog(null, "两次密码不一致");
                    return;
                }
                //2:组织参数
                UserVO vo = new UserVO();
                vo.setName(name);
                vo.setType(type);
                vo.setUuid(uuid);
                vo.setPwd(pwd1);

                //3:调用逻辑层
            ebi =  UserEbiFactory.getUserEbi();
            boolean boo = ebi.update(vo);
            if(boo){
                back();
                return;
            }
            JOptionPane.showMessageDialog(null, "修改失败");
    }

    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.JComboBox ComboBoxType;
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnUpdate;
    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.JTextField tfdpwd1;
    private javax.swing.JTextField tfdpwd2;
    private javax.swing.JTextField tfduuid;
    // End of variables declaration//GEN-END:variables

}

查询页面代码

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

package cn.hncu.bookStore.user.ui;

import java.util.List;

import javax.swing.JFrame;

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.UserQueryVO;
import cn.hncu.bookStore.user.vo.UserVO;

/**
 *
 * @author  __USER__
 */
public class QueryPanel extends javax.swing.JPanel {
    private JFrame mainFrame = null;
    //注入逻辑层ebi
    private UserEbi ebi = UserEbiFactory.getUserEbi();

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

    private void myDataInitComponcents() {
        // 初始化 用户类型选线
        for (UserTypeEnum userType : UserTypeEnum.values()) {
            ComboBoxType.addItem(userType.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();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        ComboBoxType = new javax.swing.JComboBox();
        tfdUuid = new javax.swing.JTextField();
        tfdName = new javax.swing.JTextField();
        btnback = new javax.swing.JButton();
        btnQuery = new javax.swing.JButton();

        setBackground(new java.awt.Color(204, 255, 153));
        setMinimumSize(new java.awt.Dimension(800, 600));
        setPreferredSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("黑体", 0, 36));
        jLabel1.setText("\u67e5\u8be2\u7528\u6237\u4fe1\u606f");
        add(jLabel1);
        jLabel1.setBounds(270, 40, 230, 70);

        jLabel4.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel4.setText("\u7f16\u53f7\uff1a");
        add(jLabel4);
        jLabel4.setBounds(90, 160, 90, 50);


        jLabel7.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel7.setText("\u7c7b\u578b\uff1a");
        add(jLabel7);
        jLabel7.setBounds(440, 160, 90, 50);

        jLabel8.setFont(new java.awt.Font("黑体", 0, 24));
        jLabel8.setText("\u59d3\u540d\uff1a");
        add(jLabel8);
        jLabel8.setBounds(80, 350, 90, 50);

        ComboBoxType.setFont(new java.awt.Font("黑体", 0, 24));
        ComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "选择用户类型" }));
        add(ComboBoxType);
        ComboBoxType.setBounds(530, 170, 170, 40);

        tfdUuid.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfdUuid);
        tfdUuid.setBounds(170, 160, 170, 50);

        tfdName.setFont(new java.awt.Font("黑体", 0, 24));
        add(tfdName);
        tfdName.setBounds(160, 350, 170, 50);

        btnback.setFont(new java.awt.Font("黑体", 0, 24));
        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(460, 440, 130, 40);

        btnQuery.setFont(new java.awt.Font("黑体", 0, 24));
        btnQuery.setText("\u67e5\u8be2");
        btnQuery.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQueryActionPerformed(evt);
            }
        });
        add(btnQuery);
        btnQuery.setBounds(460, 370, 130, 40);
    }// </editor-fold>
    //GEN-END:initComponents

    private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
        //1:收集参赛
        String uuid = tfdUuid.getText();
        String name = tfdName.getText();
        String strType = ComboBoxType.getSelectedItem().toString();

        int type=0;
        if(ComboBoxType.getSelectedIndex()>0){//代表用户选择了某一个选项
            type = UserTypeEnum.getTypeByName(strType);
        }
        //2:组织参数
        UserQueryVO uservo = new UserQueryVO();
        uservo.setName(name);
        uservo.setUuid(uuid);
        uservo.setType(type);

        //3:调用逻辑层
        List<UserVO> result = ebi.getByCondition(uservo);

        //4.导向结果页面
        mainFrame.setContentPane(new ListPanel(mainFrame, result));
        mainFrame.validate();
    }

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

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

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JComboBox ComboBoxType;
    private javax.swing.JButton btnQuery;
    private javax.swing.JButton btnback;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField tfdName;
    private javax.swing.JTextField tfdUuid;
    // End of variables declaration//GEN-END:variables

}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:29579次
    • 积分:2813
    • 等级:
    • 排名:第12902名
    • 原创:262篇
    • 转载:2篇
    • 译文:0篇
    • 评论:8条