程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> java書店體系卒業設計 用戶模塊(3)

java書店體系卒業設計 用戶模塊(3)

編輯:關於JAVA

java書店體系卒業設計 用戶模塊(3)。本站提示廣大學習愛好者:(java書店體系卒業設計 用戶模塊(3))文章只能為提供參考,不一定能成為您想要的結果。以下是java書店體系卒業設計 用戶模塊(3)正文


本文實例為年夜家分享了java書店體系卒業設計第3篇,供年夜家參考,詳細內容以下

import java.util.List;

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

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

/**
 *
 * @author __USER__
 */
public class listPanel extends javax.swing.JPanel {

 private static final long serialVersionUID = 1L;
 private JFrame mainFrame = null;

 public listPanel(JFrame mainFrame) {//初始化
 this.mainFrame = mainFrame;
 initComponents();
 myInitDate();
 }

 @SuppressWarnings("unchecked")
 public listPanel(JFrame mainFrame, List<UserModel> list) {
 this.mainFrame = mainFrame;
 initComponents();
 jList.setListData(list.toArray());
 }

 @SuppressWarnings("unchecked")
 private void myInitDate() {
 List<UserModel> list = UserEbiFactory.getUserEbi().getAll();
 jList.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();
 jList = new javax.swing.JList();
 btnToDelete = new javax.swing.JButton();
 btnToUpDate = new javax.swing.JButton();
 btnToQuery = new javax.swing.JButton();
 btnToAdd = new javax.swing.JButton();

 setBackground(new java.awt.Color(0, 153, 51));
 setMinimumSize(new java.awt.Dimension(800, 600));
 setLayout(null);

 jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 36));
 jLabel1.setForeground(new java.awt.Color(204, 0, 204));
 jLabel1.setText("\u7528\u6237\u7ba1\u7406");
 add(jLabel1);
 jLabel1.setBounds(330, 100, 190, 60);

 jScrollPane1.setForeground(new java.awt.Color(0, 51, 153));
 jScrollPane1.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));

 jList.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24));
 jList.setModel(new javax.swing.AbstractListModel() {
  String[] strings = { "" };

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

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

 add(jScrollPane1);
 jScrollPane1.setBounds(190, 170, 410, 220);

 btnToDelete.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
 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(240, 470, 110, 40);

 btnToUpDate.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
 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(430, 470, 110, 40);

 btnToQuery.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
 btnToQuery.setText("\u67e5\u627e\u7528\u6237");
 btnToQuery.addActionListener(new java.awt.event.ActionListener() {
  public void actionPerformed(java.awt.event.ActionEvent evt) {
  btnToQueryActionPerformed(evt);
  }
 });
 add(btnToQuery);
 btnToQuery.setBounds(600, 470, 110, 40);

 btnToAdd.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 18));
 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(60, 470, 110, 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 (jList.getSelectedValue() == null) {
  JOptionPane.showMessageDialog(this, "請選摘要修正的用戶");
  return;
 }
 String uuid = jList.getSelectedValue().toString().split(",")[0];
 mainFrame.setContentPane(new UpdatePanel(mainFrame, uuid));
 mainFrame.validate();
 }

 private void btnToDeleteActionPerformed(java.awt.event.ActionEvent evt) {
 if (jList.getSelectedValue() == null) {
  JOptionPane.showMessageDialog(this, "請選摘要刪除的用戶");
  return;
 }
 String uuid = jList.getSelectedValue().toString().split(",")[0];
 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 btnToQuery;
 private javax.swing.JButton btnToUpDate;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JList jList;
 private javax.swing.JScrollPane jScrollPane1;
 // End of variables declaration//GEN-END:variables
}

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

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

/**
 *
 * @author __USER__
 */
public class AddPanel extends javax.swing.JPanel {

 private static final long serialVersionUID = 1L;
 private JFrame mainFrame = null;

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

 @SuppressWarnings("unchecked")
 private void myinitDate() {
 combType.removeAllItems();
 for (UserTypeEnum utm:UserTypeEnum.values()) {
  combType.addItem(utm.getName());
 }
 }
 //***主動生成代碼略過***
 // </editor-fold>
 //GEN-END:initComponents

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

 private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
 String strName = tfdName.getText().trim();
 String strUuid = tfdUuid.getText().trim();
 String strPwd = new String(tfdPwd.getPassword());
 String strPwd2 =new String(tfdPwd2.getPassword());
 if (!strPwd.equals(strPwd2)) {
  JOptionPane.showMessageDialog(this, "暗碼毛病!");
  return;
 }
 String strCombType = combType.getSelectedItem().toString();

 UserModel um = new UserModel();
 um.setName(strName);
 um.setUuid(strUuid);
 um.setPwd(strPwd);
 um.setType(UserTypeEnum.getTypeByName(strCombType));

 boolean boo = UserEbiFactory.getUserEbi().create(um);

 if (boo) {
  btnCancelActionPerformed(null);
 } else {
  JOptionPane.showMessageDialog(this, "用戶已存在!");
  return;
 }

 }
 //***主動生成代碼略過***
 //GEN-BEGIN
}

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.common.UserTypeEnum;
import cn.hncu.bookStore.user.vo.UserModel;

/**
 *
 * @author __USER__
 */
public class DeletePanel extends javax.swing.JPanel {

 private static final long serialVersionUID = 1L;
 private JFrame mainFrame = null;
 private String uuid;
 UserEbi ebi = UserEbiFactory.getUserEbi();

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

 @SuppressWarnings("unchecked")
 private void myinitDate() {
 UserModel um = ebi.getSingle(uuid);
 tfdUuid.setText(uuid);
 tfdUuid.setEnabled(false);
 tfdName.setText(um.getName());
 tfdName.setEnabled(false);
 tfdPwd.setText(um.getPwd());
 tfdPwd.setEnabled(false);
 tfdPwd2.setText(um.getPwd());
 tfdPwd2.setEnabled(false);
 combType.removeAllItems();
 for (UserTypeEnum utm : UserTypeEnum.values()) {
  combType.addItem(utm.getName());
 }
 combType.setSelectedIndex(um.getType());
 combType.setEnabled(false);

 }
 //***主動生成代碼略過***
 // </editor-fold>
 //GEN-END:initComponents

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

 private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
 boolean boo = ebi.delete(uuid);

 if (boo) {
  btnCancelActionPerformed(null);
 } else {
  JOptionPane.showMessageDialog(this, "刪除用戶掉敗,用戶已不存在!");
  return;
 }
 }
 //***主動生成代碼略過***
 //GEN-BEGIN
}

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.common.UserTypeEnum;
import cn.hncu.bookStore.user.vo.UserModel;

/**
 *
 * @author __USER__
 */
public class UpdatePanel extends javax.swing.JPanel {

 private static final long serialVersionUID = 1L;
 private JFrame mainFrame = null;
 private String uuid;
 UserEbi ebi = UserEbiFactory.getUserEbi();

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

 @SuppressWarnings("unchecked")
 private void myinitDate() {
 UserModel um = ebi.getSingle(uuid);
 tfdUuid.setText(uuid);
 tfdUuid.setEnabled(false);
 tfdName.setText(um.getName());
 tfdPwd.setText(um.getPwd());
 tfdPwd2.setText(um.getPwd());
 combType.removeAllItems();
 for (UserTypeEnum utm : UserTypeEnum.values()) {
  combType.addItem(utm.getName());
 }
 combType.setSelectedIndex(um.getType());

 }
 //***主動生成代碼略過***
 // </editor-fold>
 //GEN-END:initComponents

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

 private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
 String strName = tfdName.getText().trim();
 String strUuid = tfdUuid.getText().trim();
 String strPwd = new String(tfdPwd.getPassword());
 String strPwd2 =new String(tfdPwd2.getPassword());
 if (!strPwd.equals(strPwd2)) {
  JOptionPane.showMessageDialog(this, "暗碼毛病!");
  return;
 }
 String strCombType = combType.getSelectedItem().toString();

 UserModel um = new UserModel();
 um.setName(strName);
 um.setUuid(strUuid);
 um.setPwd(strPwd);
 um.setType(UserTypeEnum.getTypeByName(strCombType));

 boolean boo = UserEbiFactory.getUserEbi().update(um);

 if (boo) {
  btnCancelActionPerformed(null);
 } else {
  JOptionPane.showMessageDialog(this, "用戶已存在!");
  return;
 }

 }
 //***主動生成代碼略過***
 //GEN-BEGIN
}

import java.util.List;

import javax.swing.JFrame;

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

/**
 *
 * @author __USER__
 */
public class QueryPanel extends javax.swing.JPanel {

 private static final long serialVersionUID = 1L;
 private JFrame mainFrame = null;

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

 @SuppressWarnings("unchecked")
 private void myinitDate() {
 combType.removeAllItems();
 combType.addItem("請選擇");
 for (UserTypeEnum utm : UserTypeEnum.values()) {
  combType.addItem(utm.getName());
 }

 }
 //***主動生成代碼略過***
 // </editor-fold>
 //GEN-END:initComponents

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

 private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
 String strName = tfdName.getText().trim();
 String strUuid = tfdUuid.getText().trim();
 String strCombType = combType.getSelectedItem().toString();

 UserQueryModel uqm=new UserQueryModel();
 uqm.setName(strName);
 uqm.setUuid(strUuid);
 int type=0;
 if(combType.getSelectedIndex()>0){
  type=UserTypeEnum.getTypeByName(strCombType);
 }
 uqm.setType(type);

 List<UserModel> list= UserEbiFactory.getUserEbi().getByCondition(uqm);
  mainFrame.setContentPane(new listPanel(mainFrame,list));
  mainFrame.validate();


 }
 //***主動生成代碼略過***
 //GEN-BEGIN
}

以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved