?? updatepanel.java
字號(hào):
package cn.javass.bookmgr.user.ui.panels;import java.awt.*;import javax.swing.JPanel;import com.borland.jbcl.layout.*;import javax.swing.*;import java.awt.event.*;import cn.javass.bookmgr.util.uiutil.ChangePanel;import cn.javass.bookmgr.MainFrame;import cn.javass.bookmgr.user.business.factory.UserFactory;import cn.javass.bookmgr.user.valueobject.UserModel;/** * 用戶模塊表現(xiàn)層用于修改用戶的Panel * * <p>Title: Java私塾第一個(gè)Java項(xiàng)目——圖書進(jìn)銷存系統(tǒng)(單機(jī)版)</p> * <p>Description: 網(wǎng)址:<a href="http://www.javass.cn">http://www.javass.cn</a> * 新電話:010-86835215 新地址:北京市海淀區(qū)廠洼路5號(hào)院深博達(dá)商務(wù)樓5層</p> * <p>Copyright: Copyright (c) 2008</p> * <p>Company: Java私塾</p> * @author Java私塾 * @version 1.0 */public class UpdatePanel extends JPanel { //以下為本界面需要的組件定義 XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); JTextField txt_userId = new JTextField(); JTextField txt_name = new JTextField(); JComboBox cmb_type = new JComboBox(); JPasswordField pwd_pwd = new JPasswordField(); JPasswordField pwd_secondpwd = new JPasswordField(); JButton btn_update = new JButton(); JButton btn_back = new JButton(); /** * 用來(lái)保持對(duì)主窗體的引用 */ MainFrame mf = null; /** * 需要修改的用戶的String值 */ String str = ""; /** * 構(gòu)建修改用戶的Panel * @param mf 主窗體的引用 * @param str 用戶的String值 */ public UpdatePanel(MainFrame mf,String str) { try { this.str = str; this.mf = mf; jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } /** * 真正進(jìn)行組件初始化,并構(gòu)建整個(gè)界面 * @throws Exception */ void jbInit() throws Exception { //1:根據(jù)傳遞過(guò)來(lái)的用戶String,轉(zhuǎn)換成為對(duì)應(yīng)的用戶Model UserModel um = new UserModel(this.str); //2:把值設(shè)置到組件上,用于顯示 this.txt_name.setText(um.getName()); this.txt_userId.setText(um.getId()); this.txt_userId.setEditable(false); this.pwd_pwd.setText(um.getPwd()); this.pwd_secondpwd.setText(um.getPwd()); this.cmb_type.addItem(UserModel.TYPE_1); this.cmb_type.addItem(UserModel.TYPE_2); this.cmb_type.addItem(UserModel.TYPE_3); this.cmb_type.addItem(UserModel.TYPE_4); this.cmb_type.addItem(UserModel.TYPE_5); this.cmb_type.addItem(UserModel.TYPE_6); //匹配下拉列表到底應(yīng)該顯示哪一條記錄 if(um.getType() == UserModel.TYPE_INT_1){ this.cmb_type.setSelectedItem(UserModel.TYPE_1); }else if(um.getType() == UserModel.TYPE_INT_2){ this.cmb_type.setSelectedItem(UserModel.TYPE_2); }else if(um.getType() == UserModel.TYPE_INT_3){ this.cmb_type.setSelectedItem(UserModel.TYPE_3); }else if(um.getType() == UserModel.TYPE_INT_4){ this.cmb_type.setSelectedItem(UserModel.TYPE_4); }else if(um.getType() == UserModel.TYPE_INT_5){ this.cmb_type.setSelectedItem(UserModel.TYPE_5); }else if(um.getType() == UserModel.TYPE_INT_6){ this.cmb_type.setSelectedItem(UserModel.TYPE_6); } jLabel1.setFont(new java.awt.Font("Dialog", 1, 30)); jLabel1.setText("修改用戶信息"); this.setLayout(xYLayout1); jLabel2.setText("用戶編號(hào)"); jLabel3.setText("用戶姓名"); jLabel4.setText("用戶類型"); jLabel5.setText("用戶密碼"); jLabel6.setText("確認(rèn)密碼"); btn_update.setText("保存"); btn_update.addActionListener(new UpdatePanel_btn_update_actionAdapter(this)); btn_back.setText("返回"); btn_back.addActionListener(new UpdatePanel_btn_back_actionAdapter(this)); this.add(jLabel1, new XYConstraints(96, 12, 377, 82)); this.add(jLabel2, new XYConstraints(13, 91, 77, 30)); this.add(jLabel3, new XYConstraints(238, 90, 77, 30)); this.add(jLabel4, new XYConstraints(13, 165, 77, 30)); this.add(jLabel5, new XYConstraints(238, 168, 77, 30)); this.add(jLabel6, new XYConstraints(13, 233, 77, 30)); this.add(txt_userId, new XYConstraints(63, 93, 166, 33)); this.add(txt_name, new XYConstraints(295, 93, 166, 33)); this.add(cmb_type, new XYConstraints(63, 163, 166, 33)); this.add(pwd_pwd, new XYConstraints(295, 167, 166, 33)); this.add(pwd_secondpwd, new XYConstraints(63, 239, 166, 33)); this.add(btn_update, new XYConstraints(142, 343, 117, 46)); this.add(btn_back, new XYConstraints(307, 343, 117, 46)); } /** * 點(diǎn)擊修改按鈕的事件處理 * @param e Action事件對(duì)象 */ void btn_update_actionPerformed(ActionEvent e) { //1:收集參數(shù) String id = this.txt_userId.getText(); String name = this.txt_name.getText(); String type = (String)this.cmb_type.getSelectedItem(); String pwd = new String(this.pwd_pwd.getPassword()); String secondPwd = new String(this.pwd_secondpwd.getPassword()); //1.1 檢測(cè)數(shù)據(jù) if(pwd==null || pwd.trim().length()==0 || secondPwd==null || secondPwd.trim().length()==0 || !pwd.trim().equals(secondPwd.trim()) ){ JOptionPane.showMessageDialog(null,"密碼不能為空,而且兩次輸入的密碼必須一致"); return; } //2:組織參數(shù) UserModel um = new UserModel(); um.setId(id); um.setName(name); um.setPwd(pwd); um.setType(um.typeStringToInt(type)); //3:調(diào)用邏輯層Api,并獲取返回值 boolean flag = UserFactory.getInstance().createUserEbi().updateUser(um); //4:根據(jù)返回值選擇新的Panel if(flag){ ChangePanel.changePanel(mf,new ListPanel(mf,false,null)); }else{ JOptionPane.showMessageDialog(null,"很遺憾,修改失敗了"); } } /** * 點(diǎn)擊返回按鈕的事件處理 * @param e Action事件對(duì)象 */ void btn_back_actionPerformed(ActionEvent e) { ChangePanel.changePanel(mf,new ListPanel(mf,false,null)); }}//以下為事件處理中的Adaper類class UpdatePanel_btn_update_actionAdapter implements java.awt.event.ActionListener { UpdatePanel adaptee; UpdatePanel_btn_update_actionAdapter(UpdatePanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.btn_update_actionPerformed(e); }}class UpdatePanel_btn_back_actionAdapter implements java.awt.event.ActionListener { UpdatePanel adaptee; UpdatePanel_btn_back_actionAdapter(UpdatePanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.btn_back_actionPerformed(e); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -