⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatepanel.java

📁 java私塾里的图书进销存项目的源代码,非常不错,J2SE基础知识复习非常有帮助!
💻 JAVA
字号:
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;/** * 用户模块表现层用于修改用户的Panel * * <p>Title: Java私塾第一个Java项目——图书进销存系统(单机版)</p> * <p>Description: 网址:<a href="http://www.javass.cn">http://www.javass.cn</a> * 新电话:010-86835215   新地址:北京市海淀区厂洼路5号院深博达商务楼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();  /**   * 用来保持对主窗体的引用   */  MainFrame mf = null;  /**   * 需要修改的用户的String值   */  String str  = "";  /**  * 构建修改用户的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();    }  }  /**   * 真正进行组件初始化,并构建整个界面   * @throws Exception   */  void jbInit() throws Exception {    //1:根据传递过来的用户String,转换成为对应的用户Model    UserModel um = new UserModel(this.str);    //2:把值设置到组件上,用于显示    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);    //匹配下拉列表到底应该显示哪一条记录    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("用户编号");    jLabel3.setText("用户姓名");    jLabel4.setText("用户类型");    jLabel5.setText("用户密码");    jLabel6.setText("确认密码");    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));  }  /**   * 点击修改按钮的事件处理   * @param e Action事件对象   */  void btn_update_actionPerformed(ActionEvent e) {    //1:收集参数    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 检测数据    if(pwd==null || pwd.trim().length()==0 || secondPwd==null || secondPwd.trim().length()==0       || !pwd.trim().equals(secondPwd.trim())       ){      JOptionPane.showMessageDialog(null,"密码不能为空,而且两次输入的密码必须一致");      return;    }    //2:组织参数    UserModel um = new UserModel();    um.setId(id);    um.setName(name);    um.setPwd(pwd);    um.setType(um.typeStringToInt(type));    //3:调用逻辑层Api,并获取返回值    boolean flag = UserFactory.getInstance().createUserEbi().updateUser(um);    //4:根据返回值选择新的Panel    if(flag){      ChangePanel.changePanel(mf,new ListPanel(mf,false,null));    }else{      JOptionPane.showMessageDialog(null,"很遗憾,修改失败了");    }  }  /**   * 点击返回按钮的事件处理   * @param e Action事件对象   */  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);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -