欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java设计模块系列之书店管理系统单机版(三)

程序员文章站 2024-03-13 12:49:03
介绍 今天对系列二的一个添加用户的输入小bug进行了解决, 增加了用户模块的,删除用户,和修改用户模块。 下面的代码是相对于系列二来说进行了修改或者是增加的类. 先看...

介绍

今天对系列二的一个添加用户的输入小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

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。