Cet article partage le troisième chapitre de la conception de graduation du système de librairie Java pour votre référence. Le contenu spécifique est le suivant
Importer java.util.list; importer javax.swing.jframe; importer javax.swing.joptionpane; import Cn.hncu.bookstore.user.business.factory.userebifactory; Importer cn.hncu.bookstore.user.vo.UserModel; / ** * * @Autor __USA javax.swing.jpanel {private statique final long serialversionuid = 1l; privé jframe mainframe = null; public listPanel (jframe mainframe) {// initialiser 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 ()); } // *** Ce paragraphe est automatiquement généré, et il ne sera pas écrit ci-dessous *** / ** Cette méthode est appelée à l'intérieur du constructeur pour * initialiser le formulaire. * AVERTISSEMENT: ne modifiez pas ce code. Le contenu de cette méthode est * toujours régénéré par l'éditeur de formulaire. * / // Gen-Begin: initComponents // <Editor-Fold defaultState = "Entreclé" desc = "Code généré"> 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 objet 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) {btntoDeteActionPerformed (evt);}}); ajouter (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);}}); ajouter (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.ADDACTIONLISTERNER (new Java.awt.Event.ActionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {btnttoQueryActionperformed (evt);}}); Add (btnttoQuery); BTNTOQUERY.SetBounds (600, 470, 110, 40); btntoadd.setfont (new java.awt.font ("Microsoft yahei ui", 1, 18)); btntoadd.setText ("/ u6dfb / u52a0 / u7528 / u6237"); btnttoadd.addactionListener (new java.awt.event.actionListener () {public void actionperformed (java.awt.event.actionEvent evt) {btnttoaddactionperformed (evt);}}); ajouter (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, "Veuillez sélectionner l'utilisateur pour modifier"); retour; } String UUID = jList.getSelectedValue (). ToString (). Split (",") [0]; mainframe.setContentPane (new UpdatePanel (mainframe, UUID)); mainframe.validate (); } private void btntodeleTectionPerformed (java.awt.event.actionEvent evt) {if (jList.getSelectedValue () == null) {joptionpane.showMessageDialog (this, "Veuillez sélectionner l'utilisateur à supprimer"); retour; } String UUID = jList.getSelectedValue (). ToString (). Split (",") [0]; mainframe.setContentPane (new DeletePanel (mainframe, uUID)); mainframe.validate (); } private void btnttoAddActionperformed (java.awt.event.actionEvent evt) {mainframe.setContentPane (new AddPanel (mainframe)); mainframe.validate (); } // *** Ce paragraphe est automatiquement généré et ne sera pas écrit ci-dessous *** // Gen-Begin: Variables // Déclaration de variables - Ne modifiez pas Javax.swing.swing.jbutton btnttoadd; privé javax.swing.jbutton btntodelete; privé javax.swing.jbutton btnttoquery; privé javax.swing.jbutton btntoupDate; privé javax.swing.jLabel JLabel1; privé javax.swing.jlist jlist; privé javax.swing.jscrollpane jscrollpane1; // Fin des variables Déclaration // Gen-End: Variables} Importer javax.swing.jframe; import javax.swing.joptionpane; import Cn.hncu.bookstore.user.business.factory.userebifactory; import Cn.hncu.BookStore.User.Common.UserTypeenum; Importer Cn.hncu.BookStore.User.vo.UserModel; __User__ * / Classe publique AddPanel étend javax.swing.jpanel {private static final long SerialVersionUID = 1l; privé jframe mainframe = null; / ** crée un nouveau formulaire addPanel * / public addPanel (jframe mainframe) {this.mainframe = mainframe; INITCOMPONENTS (); myinitdate (); } @SuppressWarnings ("Unchecked") private void myInitDate () {cobtype.removealLitems (); pour (userTypeeNum utm: userTypeeNum.values ()) {cobtype.additem (utm.getName ()); }} // *** Code de génération automatique sauts *** // </ editor-fold> // gen-end: initComponents private void btncancelACCTIONPERFORGED (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, "le mot de passe est faux!"); retour; } String strcombType = combtype.getSelectedItem (). ToString (); UserModel um = new UserModel (); um.setName (strname); um.setuuid (struuid); um.setpwd (strpwd); um.setType (userTypeeNum.getTypeByName (strCombType)); booléan boo = userebifactory.getUteRebi (). Create (um); if (boo) {btncancelACCTIONSPERFORMED (null); } else {joptionpane.showMessageDialog (this, "l'utilisateur existe déjà!"); retour; }} // *** Code généré automatique sauté *** // Gen-Begin} Importer javax.swing.jframe; import javax.swing.joptionpane; import Cn.hncu.bookstore.user.business.ebi.userebi; import Cn.hncu.bookstore.user.Business.factory.USEREBIFACTORY; Importer Cn.hncu.BookStore.User.Common.Usertypeenum; cn.hncu.bookstore.user.vo.usermodel; / ** * * @author __user__ * / classe publique Deletepanel étend javax.swing.jpanel {private statique final long SerialversionUid = 1l; privé jframe mainframe = null; chaîne privée uuid; Userebi ebi = userebifactory.getUteRebi (); / ** crée un nouveau formulaire 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 (); pour (userTypeeNum utm: userTypeeNum.values ()) {combtype.additem (utm.getName ()); } combtype.setselectedIndex (um.getType ()); combtype.setEnabled (false); } // *** Code généré automatique sauté *** // </ editor-Fold> // Gen-End: InitComponents private void btncancelACTIONGERFORGED (java.awt.event.actionEvent evt) {mainframe.setContentPane (new ListPanel (mainframe)); mainframe.validate (); } private void btndeleTectionPerformed (java.awt.event.actionEvent evt) {boolean boo = ebi.delete (uuid); if (boo) {btncancelACCTIONSPERFORMED (null); } else {joptionpane.showMessageDialog (this, "Supprimer l'utilisateur a échoué, l'utilisateur n'existe plus!"); retour; }} // *** Code généré automatique sauté *** // Gen-Begin} Importer javax.swing.jframe; import javax.swing.joptionpane; import Cn.hncu.bookstore.user.business.ebi.userebi; import Cn.hncu.bookstore.user.Business.factory.USEREBIFACTORY; Importer Cn.hncu.BookStore.User.Common.Usertypeenum; cn.hncu.bookstore.user.vo.usermodel; / ** * * @author __user__ * / classe publique UpdatePanel étend javax.swing.jpanel {private statique final long SerialVersionUID = 1l; privé jframe mainframe = null; chaîne privée uuid; Userebi ebi = userebifactory.getUteRebi (); / ** crée un nouveau formulaire 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 ()); cobtype.removealLitems (); pour (userTypeeNum utm: userTypeeNum.values ()) {cobtype.additem (utm.getName ()); } combtype.setselectedIndex (um.getType ()); } // *** Code généré automatique sauté *** // </ editor-Fold> // Gen-End: InitComponents private void btncancelACTIONGERFORGED (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, "le mot de passe est faux!"); retour; } String strcombType = combtype.getSelectedItem (). ToString (); UserModel um = new UserModel (); um.setName (strname); um.setuuid (struuid); um.setpwd (strpwd); um.setType (userTypeeNum.getTypeByName (strCombType)); booléan boo = userebifactory.getUteRebi (). Update (um); if (boo) {btncancelACCTIONSPERFORMED (null); } else {joptionpane.showMessageDialog (this, "l'utilisateur existe déjà!"); retour; }} // *** Code généré automatique sauté *** // Gen-Begin} Importer java.util.list; importer javax.swing.jframe; import Cn.hncu.bookstore.user.business.factory.userebifactory; Importer cn.hncu.bookstore.user.common.userTypeenum; cn.hncu.bookstore.user.vo.userQueryModel; / ** * * @author __user__ * / classe publique Querypanel étend javax.swing.jpanel {private statique final SerialVersionUID = 1l; privé jframe mainframe = null; / ** crée un nouveau formulaire addPanel * / public queryPanel (jframe mainframe) {this.mainframe = mainframe; INITCOMPONENTS (); myinitdate (); } @SuppressWarnings ("Unchecked") private void myInitDate () {cobtype.removealLitems (); CobType.Additem ("Veuillez sélectionner"); pour (userTypeeNum utm: userTypeeNum.values ()) {combtype.additem (utm.getName ()); }} // *** Code généré automatique sauté *** // </ 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, liste)); mainframe.validate (); } // *** Code de génération automatique sauts *** // Gen-Begin}Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.