Este artículo comparte el tercer capítulo del diseño de graduación del sistema de librería Java para su referencia. El contenido específico es el siguiente
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;/** * * * * @autor __user__ */públicas class de las clases extiende extends.vo.usermodel;/** * * * * @autor __user__ */públicas class de las clases extensas. javax.swing.jpanel {Private estático final Long SerialVersionUid = 1L; Private Jframe mainframe = null; Public ListPanel (jframe mainframe) {// inicializar esto.mainframe = mainframe; initComponents (); myInitDate (); } @Suppleswarnings ("sin verificar") Public listPanel (jframe mainframe, list <sermodel> list) {this.mainframe = mainframe; initComponents (); jlist.setListData (list.toarray ()); } @Suppleswarnings ("sin verificar") private void myInitDate () {list <Sermodel> list = userebifactory.getuserebi (). GetAll (); jlist.setListData (list.toarray ()); } // *** Este párrafo se genera automáticamente, y no se escribirá a continuación *** /** Este método se llama desde el constructor para*inicializar el formulario. * Advertencia: no modifique este código. El contenido de este método es * siempre regenerado por el editor de formulario. */// gen-begin: initComponents // <editor-fold defaultState = "collapsed" desc = "código generado"> privado 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 (nuevo Java.AWT.Color (0, 153, 51)); setMinimumSize (nuevo Java.awt.Dimension (800, 600)); setLayout (nulo); jlabel1.setFont (nuevo java.awt.font ("Microsoft Yahei UI", 1, 36)); jlabel1.setForeground (nuevo java.awt.color (204, 0, 204)); jlabel1.settext ("/u7528/u6237/u7ba1/u7406"); agregar (jlabel1); jlabel1.setBounds (330, 100, 190, 60); JScrollPane1.setForefround (nuevo Java.AWT.Color (0, 51, 153)); jscrollpane1.setFont (nuevo java.awt.font ("Microsoft Yahei ui", 1, 18)); jlist.setFont (nuevo 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); agregar (jscrollPane1); JScrollPane1.SetBounds (190, 170, 410, 220); btntodelete.setFont (nuevo 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) {btntodelElteActionperformed (evt);}}); agregar (btntodelete); btntodelete.setBounds (240, 470, 110, 40); btntoupdate.setFont (nuevo 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);}}); agregar (btntoupdate); btntoupdate.setBounds (430, 470, 110, 40); btntoQuery.setFont (nuevo 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);}}); agregar (btntoQuery); btntoQuery.setBounds (600, 470, 110, 40); btntoadd.setfont (nuevo 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);}}); agregar (btntoadd); btntoadd.setBounds (60, 470, 110, 40); } // </editor-fold> // gen-end: initComponents private void btntoQueryactionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (new QeryPanel (mainframe)); mainframe.validate (); } private void btnToupDataActionperformed (java.awt.event.actionEvent evt) {if (jList.getSelectedValue () == null) {joptionPane.showMessageEdialog (esto ", seleccione el usuario para modificar"); devolver; } String uuid = jList.getSelectedValue (). ToString (). Split (",") [0]; mainframe.setContentPane (nuevo updatePanel (mainframe, uuid)); mainframe.validate (); } private void btnTodelElteCactionperformed (java.awt.event.actionEvent evt) {if (jlist.getSelectedValue () == null) {joptionPane.showMessEdialog (esto, "seleccione el usuario para delete"); devolver; } String uuid = jList.getSelectedValue (). ToString (). Split (",") [0]; mainframe.setContentPane (nuevo DeletePanel (mainframe, uuid)); mainframe.validate (); } private void btntoaddactionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (new AddPanel (mainframe)); mainframe.validate (); } // *** Este párrafo se genera automáticamente, y no se escribirá a continuación *** // Gen -Begin: Variables // Declaración de variables - No modifique javax.swing.jbutton btntoadd; privado javax.swing.jbutton btntodelete; Javax.swing privado. JButton BtntoQuery; privado javax.swing.jbutton btntoupdate; privado javax.swing.jlabel jlabel1; privado javax.swing.jlist jlist; privado javax.swing.jscrollpane jscrollpane1; // Declaración de finales de variables // 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 extiende javax.swing.jpanel {private static final long serialversionUid = 1l; Private Jframe mainframe = null; / ** Crea una nueva forma addpanel*/ public addpanel (jframe mainframe) {this.mainframe = mainframe; initComponents (); myInitDate (); } @Suppleswarnings ("sin control") privado void myinitdate () {cobtype.removeallitems (); para (usertypeenum utm: usertypeenum.values ()) {cobtype.additem (utm.getName ()); }} // *** Código de generación automática Skips *** // </editor-fold> // gen-end: initComponents private void btncancelactionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (nuevo listpanel (mainframe)); mainframe.validate (); } private void btnaddactionperformed (java.awt.event.actionEvent evt) {string strname = tfdname.gettext (). trim (); Cadena struuid = tfduuid.gettext (). Trim (); String strpwd = new String (tfdpwd.getpassword ()); String strpwd2 = new String (tfdpwd2.getPassword ()); if (! strpwd.equals (strpwd2)) {joptionPane.showMessEdialog (esta, "¡La contraseña está mal!"); devolver; } 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.showMessEdialog (esto, "¡El usuario ya existe!"); devolver; }} // *** Código generado automático omitido *** // 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.usertypoenum; cn.hncu.bookstore.user.vo.usermodel;/** * * @author __user__ */public class DeletePanel extiende javax.swing.jpanel {private Static final Long SerialVersionUid = 1l; Private Jframe mainframe = null; cadena privada uuid; Userebi ebi = userebifactory.getuserebi (); / ** Crea una nueva forma addpanel*/ public deletepanel (jframe mainframe, string uuid) {this.mainframe = mainframe; this.uuid = uuid; initComponents (); myInitDate (); } @Suppleswarnings ("sin verificar") private void myInitDate () {usermodel um = ebi.getsingle (uuid); tfduuid.settext (uuid); tfduuid.setEnabled (falso); tfdname.settext (um.getName ()); tfdname.setEnabled (falso); tfdpwd.settext (um.getpwd ()); tfdpwd.setEnabled (falso); tfdpwd2.settext (um.getpwd ()); tfdpwd2.setEnabled (falso); combtype.removeallitems (); para (usertypeenum utm: usertypeenum.values ()) {combtype.additem (utm.getName ()); } combtype.setselectedIndex (um.gettype ()); combtype.setEnabled (falso); } // *** Código generado automático omitió *** // </ editor-fold> // gen-end: initComponents private void btncancelactionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (nuevo listpanel (mainframe)); mainframe.validate (); } private void btndeleteActionperformed (java.awt.event.actionEvent evt) {boolean boo = ebi.delete (uuid); if (boo) {btncancelactionperformed (null); } else {joptionPane.showMessEdialog (esto, "Eliminar el usuario fallido, ¡el usuario ya no existe!"); devolver; }} // *** Código generado automático omitido *** // 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.usertypoenum; cn.hncu.bookstore.user.vo.usermodel;/** * * @author __user__ */public class UpdatePanel extiende javax.swing.jpanel {private Static final Long SerialVersionUid = 1l; Private Jframe mainframe = null; cadena privada uuid; Userebi ebi = userebifactory.getuserebi (); / ** Crea una nueva forma addpanel*/ public updatePanel (jframe mainframe, string uuid) {this.mainframe = mainframe; this.uuid = uuid; initComponents (); myInitDate (); } @Suppleswarnings ("sin verificar") private void myInitDate () {usermodel um = ebi.getsingle (uuid); tfduuid.settext (uuid); tfduuid.setEnabled (falso); tfdname.settext (um.getName ()); tfdpwd.settext (um.getpwd ()); tfdpwd2.settext (um.getpwd ()); COBTYPE.REMOVEALLITEMS (); para (usertypeenum utm: usertypeenum.values ()) {cobtype.additem (utm.getName ()); } combtype.setselectedIndex (um.gettype ()); } // *** Código generado automático omitió *** // </ editor-fold> // gen-end: initComponents private void btncancelactionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (nuevo listpanel (mainframe)); mainframe.validate (); } private void btnupDataActionParformed (java.awt.event.actionEvent evt) {string strname = tfdname.getText (). trim (); Cadena struuid = tfduuid.gettext (). Trim (); String strpwd = new String (tfdpwd.getpassword ()); String strpwd2 = new String (tfdpwd2.getPassword ()); if (! strpwd.equals (strpwd2)) {joptionPane.showMessEdialog (esta, "¡La contraseña está mal!"); devolver; } 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.showMessEdialog (esto, "¡El usuario ya existe!"); devolver; }} // *** Código generado automático omitido *** // 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 extiende javax.swing.jpanel {private estático final long SerialVersionUid = 1l; Private Jframe mainframe = null; / ** Crea una nueva forma addpanel*/ public querypanel (jframe mainframe) {this.mainframe = mainframe; initComponents (); myInitDate (); } @Suppleswarnings ("sin control") privado void myinitdate () {cobtype.removeallitems (); cobtype.additem ("por favor seleccione"); para (usertypeenum utm: usertypeenum.values ()) {combtype.additem (utm.getName ()); }} // *** Código generado automático omitió *** // </ editor-fold> // gen-end: initComponents private void btncancelactionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (nuevo listpanel (mainframe)); mainframe.validate (); } private void btnQueryActionperformed (java.awt.event.actionEvent evt) {string strname = tfdname.gettext (). trim (); Cadena struuid = tfduuid.gettext (). Trim (); Cadena strcombtype = combtype.getelectedItem (). ToString (); UserQueryModel uqm = new UserQueryModel (); uqM.SetName (strname); uqM.SetUuid (struuid); int type = 0; if (combtype.getSelectedIndex ()> 0) {type = usertypeenum.gettypeByName (strcombtype); } uqm.settype (tipo); Lista <SerModel> list = userebifactory.getuserebi (). GetByCondition (uqm); mainframe.setContentPane (nuevo listPanel (mainframe, list)); mainframe.validate (); } // *** Código de generación automática Skips *** // Gen-Begin}Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.