Les exemples de cet article partagent avec vous le code spécifique de Java pour implémenter le système de gestion des bibliothèques pour votre référence. Le contenu spécifique est le suivant
/ * (Le commentaire de l'en-tête du programme commence)
* Copyright et déclaration de la partie du programme
* Copyright (c) 2011, École d'informatique de l'Université de Yantai
* Tous droits réservés.
* Nom du fichier: "Système de gestion du livre-java"
* Auteur: Liu Jiangbo
* Date d'achèvement: 1er mars 2012
* Numéro de version: v3.0
* Description des tâches et des solutions
* Description de la question:
* La fin des commentaires en tête du programme
* /
État de la création de packages de fichiers:
Bookdao.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / package com.liu.dao; Importer com.liu.po.bookbean; importer java.io. *; import java.util.hashmap; importation java.util.map; import java.util.logging.level; import java.util.logging.logger; / ** * * @author asus * / public class bookdao {// write public void writebook (map <Integer, bookBean> bookmap) {// fileOutputStream fos = null; ObjectOutputStream oos = null; essayez {fos = new FileOutputStream ("f: //cache//book.txt"); OOS = new ObjectOutputStream (FOS); oos.writeObject (Bookmap); // effacer le cache oos.flush (); } catch (filenotfoundException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); } // Le niveau d'exception est à la fin de catch (ioException ex) {logger.getLogger (typedao.class.getName ()). Log (niveau.severe, null, ex); } enfin {try {// ouvrir et fermer oos.close (); fos.close (); } catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); }}} // Lire la carte publique <Integer, bookBean> ReadBook () {fileInputStream fis = null; ObjectInputStream oiS = null; Map <Integer, bookBean> map = null; essayez {fis = new FileInputStream ("f: //cache//book.txt"); OIS = new ObjectInputStream (FIS); map = (map <nteger, bookBean>) ois.readObject (); // l'exception se produit et entre Catch} catch (classNotFoundException ex) {logger.getLogger (typedao.class.getName ()). Log (niveau.severe, null, ex); } catch (filenotfoundException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); } catch (ioException ex) {//logger.getLogger(Typedao.class.getName()).log(level.severe, null, ex); //ex.printStackTrace (); map = new HashMap <Integer, bookBean> (); // créer map} enfin {try {if (ois! = null) {ois.close (); } if (fis! = null) {fis.close (); }} catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); }} retour de retour; }}Typedao.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / package com.liu.dao; import com.liu.po.typebean; importer java.io. *; import java.util. *; importer java.util.logging. *; / ** * * Lire et écrire des fichiers * / classe publique typedao {// écrire public void writeType (map <Integer, typeBean> tymap) {// fileoutputStream fos = null; ObjectOutputStream oos = null; essayez {fos = new FileOutputStream ("f: //cache//type.txt"); OOS = new ObjectOutputStream (FOS); oos.writeObject (tymap); // effacer le cache oos.flush (); } catch (filenotfoundException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); } // Le niveau d'exception est à la fin (ioException ex) {Logger.getLogger (typedao.class.getName ()). Log (NIVEAL.SEVERE, NULL, EX); } enfin {try {// Ouvrir d'abord puis fermer oos.close (); fos.close (); } catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); }}} // Lire la carte publique <Integer, TypeBean> ReadType () {FileInputStream fis = null; ObjectInputStream oiS = null; Map <Integer, typeBean> map = null; try {fis = new FileInputStream ("f: //cache//type.txt"); OIS = new ObjectInputStream (FIS); map = (map <nteger, typeBean>) ois.readObject (); // l'exception se produit et entre Catch} catch (classNotFoundException ex) {logger.getLogger (typedao.class.getName ()). Log (niveau.severe, null, ex); } catch (filenotfoundException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); } catch (ioException ex) {//logger.getLogger(Typedao.class.getName()).log(level.severe, null, ex); //ex.printStackTrace (); map = new HashMap <Integer, typeBean> (); // Créer Map} Enfin {try {if (ois! = null) {ois.close (); } if (fis! = null) {fis.close (); }} catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (niveau.severe, null, ex); }} retour de retour; }}}Bookbean.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / package com.liu.po; import java.io.serializable; / ** * * @author asus * / public class bookBean implémente serializable {private int id; BookName à chaîne privée; BookType de chaîne privée; Mémo de chaîne privée; argent de cordes privées; / ** * @return l'ID * / public int getID () {return id; } / ** * @param id L'ID pour définir * / public void setid (int id) {this.id = id; } / ** * @return The BookName * / public String getBookName () {return bookName; } / ** * @param bookname Le nom de livre pour définir * / public void setBookName (String bookName) {this.bookname = bookName; } / ** * @return The BookType * / public String getBookType () {return bookType; } / ** * @param bookType Le bookType à définir * / public void setBookType (String bookType) {this.booktype = bookType; } / ** * @return The Memo * / public String getmemo () {return memo; } / ** * @param Mémo la note à définir * / public void setmemo (String memo) {this.memo = mémo; } / ** * @return l'argent * / public String getMoney () {return money; } / ** * @param argent l'argent pour définir * / public void setMoney (String Money) {this.money = money; }}Typebean.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / package com.liu.po; / ** * * @author asus * / import java.io.serializable; classe publique TypeBean implémente Serializable {private int id; chaîne privée typename; Mémo de chaîne privée; / ** * @return l'ID * / public int getID () {return id; } / ** * @param id L'ID pour définir * / public void setid (int id) {this.id = id; } / ** * @return the typename * / public String getTyPename () {return typename; } / ** * @param typEname le typename pour définir * / public void setTyPename (String typename) {this.typename = typEname; } / ** * @return The Memo * / public String getmemo () {return memo; } / ** * @param Mémo la note à définir * / public void setmemo (String memo) {this.memo = mémo; }}Liginform.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / / * * Loginform.java * * Créé le 2013-26, 18:33:36 * / package com.liu.view; Importer java.awt.event.keyAdapter; Importer java.awt.event.KeyEvent; import javax.swing.joptionpane; / ** * * @author asus * / public class Loginform étend javax.swing.jframe {/ ** crée un nouveau formulaire LoginForm * / public LoginForm () {initComponents (); } / ** 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. * / @SuppressWarnings ("Unchecked") // <Editor-Fold defaultState = "ENCHAPSED" DESC = "Code généré"> private void initComponents () {jLabel1 = new Javax.swing.jLabel (); jLabel2 = new Javax.swing.jLabel (); jLabel3 = new Javax.swing.jLabel (); LoginName = new Javax.swing.jTextField (); Loginpwd = new javax.swing.jpasswordfield (); jbutton1 = new javax.swing.jbutton (); setDefaultCloseOperation (javax.swing.windowconstants.exit_on_close); setTitle ("Interface de connexion"); SetBounds (new Java.awt.rectangle (300, 200, 0, 0)); setIConImage (new Javax.swing.imageIcon (getClass (). getResource ("/ com / liu / resouce / logo.jpg")). getImage ()); addKeyListener (new java.awt.event.keyAdapter () {public void keyPressed (java.awt.event.kevent evt) {formkeyPressed (evt);}}); jLabel1.setfont (new Java.awt.font ("宋体", 0, 36)); JLabel1.setForeground (new Java.awt.Color (204, 0, 0)); jLabel1.seTText ("宋体"); jLabel2.setfont (new Java.awt.font ("宋体", 0, 24)); JLabel2.SeTText ("nom d'utilisateur:"); JLabel3.Setfont (new Java.awt.font ("宋体", 0, 24)); JLabel3.SeTText ("Mot de passe:"); LoginName.SetName (""); // NOI18N LoginName.AddActionListener (new Java.awt.Event.ActionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {LoginNameActionPerformed (evt);}}); LoginName.AddKeyListener (new Java.awt.Event.KeyAdapter () {public void keyPressed (java.awt.event.keyEvent evt) {LoginNameKeyPressed (evt);}}); Loginpwd.addkeyListener (new java.awt.event.keyAdapter () {public void keypressed (java.awt.event.keyEvent evt) {loginpwdkeypressed (evt);}}); jbutton1.setfont (new java.awt.font ("安一", 0, 24)); // NOI18N JBUTTON1.SETTEXT ("Login"); jbutton1.addactionListener (new java.awt.event.actionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {jbutton1actionperformed (evt);}}); javax.swing.grouplayout Layout = new javax.swing.grouplayout (getContentPane ()); getContentPane (). setLayout (Layout); Layout.SethorizontalGroup (Layout.CreateParalleGroup (javax.swing.groupuip .AddComponent (JLabel2) .AddComponent (JLabel3)) .AddPreferRedGap (javax.swing.layoutStyle. .AddComponent (Loginname, javax.swing.grouplayout.default_size, 215, short.max_value)) .addconntainergap (88, short.max_value)) .AddGroup (javax.swing.grouplayout.Alignment.Troiling, mise en page. Short.max_value) .AddComponent (JLabel1, javax.swing.grouplayout.preferred_size, 263, javax.swing.grouplayout.preferred_size) .addgap (113, 113, 113)) .AddGroup (javax.swing.grouplayout.Alignment.Trail, traillif. .AddContainergap (299, short.max_value) .addComponent (jbutton1, javax.swing.grouplayout.preferred_size, 97, javax.swing.grouplayout.preferred_size) .addgap (110, 110))); Layout.setverticalGroup (Layout.CreateParalleGroup (javax.swing.grouplayout.alignment.leading) .addGroup (Layout.CreateEquentialGroup () .Addgap (50, 50, 50) .AddComponent (jLabel1, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size, 45, javax.swing.grouplayout.preferred_size) .addgap (38, 38, 38) .AddGroup (Layout.CreateParallelGroup (javax.swing.grouplayout.alignment.baseline) .addcomponent (JLabel2) .addcomponent (Loginname, javax.swing.grouplayout.prefer_swice,, javax.swing.grouplayout.prefer_swame,, javax.swing.grouplayout.prefer_swame,, javax.swing.grouplayout.prefer_swame, Javax.Swing.grouplayOut.Prefer_swame, Javax.Swing.grouplayout.Prefer_Sefert 29, javax.swing.grouplayout.preferred_size)) .Addgap (26, 26, 26) .AddGroup (Layout.CreateParallelGroup (javax.swing.grouplayout.alignment.baseline) .addcomponent (jLabel3) .addcomponent (Loginpwdd, javax.swing.grouplayout. 29, javax.swing.grouplayout.preferred_size)) .addgap (18, 18, 18) .AddComponent (jbutton1, javax.swing.grouplayout.preferred_size, 36, javax.swing.grouplayout.preferred_size) .addcontreergap (21, short.max_valuue)). paquet(); } // </dditor-fold> private void LoginNameActionPerformed (java.awt.event.actionEvent evt) {// todo ajouter votre code de manutention ici:} private void jbutton1actionperformed (java.awt.event.actionEvent evt) {// 1. Obtenez le nom d'utilisateur et le mot de passe First String Name = LoginName.GetText (); String mot de passe = new String (loginpwd.getPassword ()); // 2. Vérifiez if ("admin" .equals (name) && "admin" .equals (mot de passe)) {// connexion avec succès // masquer le loginform et afficher mainform this.setVisible (false); new MainForm (). setVisible (true); } else {// Login a échoué jOptionPane.showMessageDialog (this, "Username ou Motway Error!"); }} private void FormKeepressed (java.awt.event.keyevent evt) {// Appuyez sur le clavier pour connecter} private void LoginNameKeyPressemired (java.awt.event.kevent evt) {// appuyez sur le clavier pour se connecter si (evt.getkeyText (evtkeycode ()). jbutton1.doclick (); }} private void LoginpwdKeyPressemiss (java.awt.event.keyevent evt) {// Appuyez sur le clavier pour connecter if (evt.getKeyText (evt.getKeyCode ()). CompareToIGNoreCase ("Entrée") == 0) {jbutton1.doclick (); }} / ** * @param args les arguments de ligne de commande * / public static void main (String args []) {java.awt.eventqueue.invokelater (new runnable () {public void run () {new LoginForm (). setVisible (true);}}); } // Déclaration de variables - Ne modifiez pas Javax.swing.jtextfield LoginName; privé javax.swing.jpasswordfield LoginPWD; Private Javax.swing.jbutton JBUTTON1; privé javax.swing.jLabel JLabel1; privé javax.swing.jLabel JLabel2; privé javax.swing.jLabel JLabel3; // Fin de la déclaration variable}Mainform.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / / * * Mainform.java * * Créé le 2013-26, 18:35:25 * / package com.liu.view; / ** * * @author asus * / public class Mainform étend javax.swing.jframe {/ ** crée un nouveau formulaire MainForm * / public mainform () {initComponents (); } / ** 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. * / @SuppressWarnings ("Unchecked") // <Editor-Fold defaultState = "ENCHAPSED" DESC = "Code généré"> private void initComponents () {jLabel1 = new Javax.swing.jLabel (); jpanel1 = new javax.swing.jpanel (); jLabel2 = new Javax.swing.jLabel (); jMenubar1 = new Javax.swing.jMenubar (); Configuration Management = new Javax.swing.jMenUiTem1 = new Javax.swing.jMenuem (); jMenuItem2 = new Javax.swing.jMenuem (); jmenu2 = new javax.swing.jmecutem (); jMenuItem3 = new Javax.swing.jMenuem (); setDefaultCloseOperation (javax.swing.windowconstants.exit_on_close); SettItle ("Système de gestion des livres"); SetBounds (new Java.awt.rectangle (80, 60, 0, 0)); setIConImage (new Javax.swing.imageIcon (getClass (). getResource ("/ com / liu / resouce / logo.jpg")). getImage ()); jLabel1.setfont (new Java.awt.font ("安体", 0, 48)); jLabel1.setForeground (new Java.awt.Color (0, 204, 51)); JLabel1.seTICon (new Javax.swing.imageIcon (getClass (). getResource ("/ com / liu / resouce / main.jpg"))); // NOI18N JLABEL2.SETFONT (new Java.awt.font ("安一", 0, 48)); JLabel2.SetForeground (new Java.awt.Color (0, 0, 255)); JLabel2.SeTText ("Bienvenue à utiliser le système de gestion d'emprunt du livre"); javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout (jpanel1); jpanel1.setLayout (jpanel1layout); jpanel1layout.sethorizontalgroup (jpanel1layout.createparallegroup (javax.swing.grouplayout.alignment.leading) .addGroup (jpanel1layout.createsentialGroup () .addgap (38, 38, 38) .addcomponent (jLabel2) .adcontainerg (68) .addcomponent (jLabel2) .adcontainerg (68). Short.max_value))); jpanel1layout.setverticalGroup (jpanel1layout.createparallelGroup (javax.swing.grouplayout.alignment.leading) .AddGroup (javax.swing.grouplayout.alignment.trailing, jpanel1layout.createseablegroup () .addContaingapap () .addomber (JLabel2,. javax.swing.grouplayout.default_size, 78, short.max_value))); Configuration Management.SeTText ("Configuration Management"); JMenuItem1.setaccelerator (javax.swing.keystroke.getkeystroke (java.awt.event.keyevent.vk_l, java.awt.event.inputevent.ctrl_mask)); JMenuItem1.seTText ("Management de catégorie"); JMenuItem1.AddActionListener (new Java.awt.Event.ActionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {jMenuItem1Actionperformed (evt);}}); Configuration Management.Add (JMenuItem1); JMenuItem2.Setaccelerator (javax.swing.keystroke.getkeystroke (java.awt.event.keyevent.vk_t, java.awt.event.inputevent.ctrl_mask)); JMenuItem2.SeTText ("Management du livre"); JMenuItem2.AddActionListener (new Java.awt.Event.ActionListener () {public void ActionperFormEd (java.awt.event.actionEvent evt) {jMenuItem2Actionperformed (evt);}}); Configuration Management.Add (JMenuItem2); JMenubar1.Add (gestion de la configuration); JMENU2.SETTEXT ("Emprunt"); JMenuItem4.Setaccelerator (javax.swing.keystroke.getkeystroke (java.awt.event.keyevent.vk_j, java.awt.event.inputevent.ctrl_mask)); JMenuItem4.SeTText ("Lease"); JMENU2.ADD (JMenuItem4); JMenubar1.Add (JMenU2); JMenu1.seTText ("Retour au livre"); JMenuItem3.SetAccelerator (javax.swing.keystroke.getkeystroke (java.awt.event.keyevent.vk_h, java.awt.event.inputevent.ctrl_mask)); JMenuItem3.SeTText ("Retour au livre"); JMenu1.Add (JMenuItem3); JMenubar1.Add (JMenu1); setjMenubar (JMenubar1); javax.swing.grouplayout Layout = new javax.swing.grouplayout (getContentPane ()); getContentPane (). setLayout (Layout); Layout.SethorizontalGroup (Layout.CreateParalleGroup (javax.swing.grouplayout.alignment.leading) .addComponent (JLabel1, 0, 0, Short.Max_Value) .AddDgroup (Layout.CreateEqualleGroup () .addgap (22, 22, 22). javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addContainergap ())); Layout.SetVerticalGroup (Layout.CreateParallelGroup (javax.swing.grouplayout.Alignment.Leading) .AddGroup (javax.swing.grouplayout.alignment.trailing, Layout.CreateseAntialGroup () .AddContainGap () .AddComponent (jpanel1,. javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addpreferredgap (javax.swing.layoutstyle javax.swing.grouplayout.preferred_size))); paquet(); } // </ editor-fold> private void jMenuItem1actionperformed (java.awt.event.actionEvent evt) {// Type Management new TypeForm (). setVisible (true); } private void jMenuItem2Actionperformed (java.awt.event.actionEvent evt) {// Book Management new bookform (). setVisible (true); } / ** * @param args les arguments de ligne de commande * / public static void main (String args []) {java.awt.eventqueue.invokelater (new runnable () {public void run () {new MainForm (). setVisible (true);}}); } // Déclaration de variables - Ne modifiez pas Javax.swing.swing.jLabel JLabel1; privé javax.swing.jLabel JLabel2; privé javax.swing.jmenu jmenu1; privé javax.swing.jMenuitem JMenuItem2; privé javax.swing.jMenuitem JMenuItem2; privé javax.swing.jMenuitem JMenuItem3; privé javax.swing.jMenuitem JMenuItem3; privé javax.swing.jMenuitem JMenuItem4; privé javax.swing.jpanel jpanel1; Private Javax.swing.jmenu Configuration Management; // Déclaration de fin des variables}Bookform.java
/ * * Pour modifier ce modèle, choisissez des outils | Modèles * et ouvrez le modèle dans l'éditeur. * / / * * Bookform.java * * créé le 2013-28, 8:23:01 * / package com.liu.view; import com.liu.dao.bookdao; import com.liu.dao.typedao; Importer com.liu.po.bookbean; import com.liu.po.typebean; importation java.util.map; import java.util.set; Importer java.util.vector; importer javax.swing.defaultcomboBoxModel; import javax.swing.joptionpane; import javax.swing.table.defaultTableModel; / ** * * @author asus * / public class bookform étend javax.swing.jframe {/ ** crée un nouveau formulaire BookForm * / map privé <Integer, bookBean> map; Carte privée <Integer, TypeBean> Map1; bookdao privé bookdao; Typedao privé typedao; public bookform () {initComponents (); bookdao = new bookdao (); typedao = new typedao (); map = bookdao.readbook (); map1 = typedao.readType (); initType (); initdata (); } / ** 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. * / @SuppressWarnings ("Unchecked") // <editor-Fold defaultState = "Entrecked" desc = "Code généré"> private void initComponents () {jpanel1 = new javax.swing.jpanel (); jscrollpane1 = new javax.swing.jscrollpane (); bookTable = new Javax.swing.jTable (); jpanel2 = new javax.swing.jpanel (); bmemo = new javax.swing.jtextfield (); jbutton1 = new javax.swing.jbutton (); jbutton2 = new javax.swing.jbutton (); jbutton3 = new javax.swing.jbutton (); jbutton4 = new javax.swing.jbutton (); jLabel1 = new Javax.swing.jLabel (); jLabel2 = new Javax.swing.jLabel (); jLabel3 = new Javax.swing.jLabel (); jLabel4 = new Javax.swing.jLabel (); bid = new javax.swing.jtextfield (); bname = new javax.swing.jtextfield (); btype = new Javax.swing.jcomboBox (); jLabel5 = new Javax.swing.jLabel (); bmoney = new javax.swing.jtextfield (); Setttitle ("gestion du livre"); SetBounds (new Java.awt.rectangle (100, 50, 0, 0)); setIConImage (new Javax.swing.imageIcon (getClass (). getResource ("/ com / liu / resouce / logo.jpg")). getImage ()); booktable.setfont (new java.awt.font ("安一", 0, 18)); // NOI18N BookTable.SetModel (New Javax.swing.Table.defaultTableModel (nouvel objet [] [] {{null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null,},},}, null, null, null, null}, {null, null, null, null, nul Null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, nul "Type de livre", "Rent", "Remarques"}) {class [] types = new class [] {java.lang.integer.class, java.lang.string.class, java.lang.string.class.class}; false, false, false, faux}; booktable.addmouseListener (new java.awt.event.mouseadapter () {public void mouseclicked (java.awt.event.mousevent evt) {booktableMouseClicked (evt);}}); jscrollpane1.setViewportView (booktable); jpanel2.setborder (javax.swing.borderfactory.createTitledBorder (null, "Détails", javax.swing.border.titledborder.default_position, new Java.awt.font ("宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体 宋体" // NOI18N BMEMO.Setfont (new Java.awt.font ("宋体", 0, 18)); JBUTTON1.SETTEXT ("NOUVEAU"); jbutton1.addactionListener (new java.awt.event.actionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {jbutton1actionperformed (evt);}}); JBUTTON2.SETTEXT ("SAVE"); JBUTTON2.AddActionListener (new Java.awt.Event.ActionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {jbutton2actionperformed (evt);}}); JBUTTON3.SETTEXT ("Update"); JBUTTON3.AddActionListener (new Java.awt.Event.ActionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {jbutton3actionperformed (evt);}}); JBUTTON4.SETTEXT ("Delete"); JBUTTON4.AddActionListener (new Java.awt.Event.ActionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {jbutton4actionperformed (evt);}}); jLabel1.setfont (new Java.awt.font ("宋体", 0, 18)); JLabel1.seTText ("宋体", 0, 18)); JLabel2.SeTText ("宋体", 0, 18)); JLabel2.SeTText ("宋体" .font ("宋体", 0, 18)); JLabel3.SeTText ("宋体", 0, 18)); JLabel3.SeTText ("宋体", 0, 18)); JLabel4.SeTText ("宋体"); JLabel4.SeTText ("宋体"); bid.setfont (new java.awt.font ("宋体", 0, 18)); bname.setfont (new java.awt.font ("宋体", 0, 18)); btype.setfont (new java.awt.font ("宋体", 0, 18)); btype.setmodel (new Javax.swing.defaultcomboBoxModel (nouvelle chaîne [] {"littérature", "éducation", "technologie", "littérature"})); btype.addactionListener (new java.awt.event.actionListener () {public void ActionPerformed (java.awt.event.actionEvent evt) {bTypeActionPerformed (evt);}}); JLabel5.Setfont (new Java.awt.font ("宋体", 0, 18)); JLabel5.SeTText ("Rent:"); javax.swing.grouplayout jpanel2layout = new javax.swing.grouplayout (jpanel2); jpanel2.setLayout (jpanel2layout); jpanel2layout.sethorizontalGroup (jpanel2layout.createParalleGroup (javax.swing.grouplayout.alignment.leading) .AddGroup (jpanel2layout.CreateEquentialGroup () .addgap (33, 33, 33) .AddGroup (jpanel2Layout.CreateParalleGroup (javax.swing.groupuip .AddComponent (JLabel2, javax.swing.grouplayout.default_size, 83, short.max_value) .AddGroup (jpanel2layout.trailing) .addcomponent (javax.swing.grouplayout.alignment.traight) .addcomponent (JLabel3) .adddComponent (JLabel5). .AddComponent (JLabel4))) .AddPreferRedGap (javax.swing.layoutStyle.Componentplacement.Related)) .AddGroup (jpanel2Layout.CreateEquentialGroup () .AddComponent (JLabel1) .addgap (33, 33, 33)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(bmemo, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) .addComponent(bmoney, javax.swing.GroupLayout.DEFAULT_SIZE, 375, short.max_value) .AddComponent (bmoney, javax.swing.grouplayout.default_size, 375, short.max_value) .adddcomponent (bmoney, javax.swing). javax.swing.grouplayout.default_size, 375, short.max_value) .addgroup (jpanel2layout.createsequentialgroup () .addcomponent (jbutton1, javax.swing.grouplayout.preferred_size) .Addgap (28, 28, 28) .AddComponent (JButton2, javax.swing.grouplayout.preferred_size, 69, javax.swing.grouplayout.preferred_size) .addgap (30, 30, 30) .addcomponent (jbutton3, javax.swing.grouplayout. javax.swing.grouplayout.preferred_size) .addpreferredgap (javax.swing.layoutstyle.componentplacement.related, 28, short.max_value) .addcomponent (jbutton4, javax.swing.grouplayout.preferred_size, 74, Javax.swing.grouplayout.preferred_size, 74, javax.swing.grouplayout.preferred_size)) .AddComponent (btype, 0, 375, short.max_value)) .addgap (65, 65, 65)))); jpanel2layout.setVerticalGroup (jpanel2layout.createParalleGroup (javax.swing.grouplayout.alignment.leading) .addgroup (javax.swing.grouplayout.alignment.trailing, jpanel2layout.createseablegroup () .addContaingap ()) .AddGroup (jpanel2layout.createParalleGroup (javax.swing.grouplayout.alignment.baseline) .addComponent (jLabel1, javax.swing.grouplayout.preferred_size, 25, javax.swing.grouplayout.preferred_size) .adddComponent (bid, javax.swing.grouplayout.preferred_size, 37, javax.swing.grouplayout.preferred_size)) .addgap (13, 13, 13) .addgroup (jpanel2layout.createparallelgroup (javax.swing.grouplayout.alignment.baseline). .AddComponent (BName, javax.swing.grouplayout.preferred_size, 37, javax.swing.grouplayout.preferred_size)) .addgap (18, 18, 18) .addgroup (jpanel2layout.createparallegroup (javax.swing.grouple .AddComponent (JLabel3) .AddComponent (Btype, javax.swing.grouplayout.preferred_size, 30, javax.swing.grouplayout.preferred_size)) .addgap (26, 26, 26) .AddGroup (jpanel2layout.createParalleGroup (javax.swing.grouplayout.alignment.baseline) .addComponent (jLabel5) .addComponent (bmoney, javax.swing.grouplayout.preferred_size) .Addgap (32, 32, 32) .AddGroup (jpanel2Layout.CreateParalleGroup (javax.swing.grouplayout.alignment.leading) .addGroup (jpanel2layout.createsequentialproup () .AddComponent (bme8, javax.swing.grouplated. javax.swing.grouplayout.preferred_size) .addgap (64, 64, 64) .AddGroup (jpanel2Layout.CreateParalleGroup (javax.swing.grouplayout.alignment.baseline) .AddComponent (jbutton1, javax.swing.grouplayout.Preferred_Size, 32, Javax.swing.grouplayout. javax.swing.grouplayout.preferred_size) .AddComponent (jbutton2, javax.swing.grouplayout.preferred_size, 32, javax.swing.grouplayout.preferred_size) .adddomponent (jbutton3, javax.swing.grouplayout. javax.swing.grouplayout.preferred_size) .AddComponent (jbutton4, javax.swing.grouplayout.preferred_size, 32, javax.swing.grouplayout.preferred_size))) .AddComponent (JLabel4)) .Addgap (22, 22, 22))); javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout (jpanel1); jpanel1.setLayout (jpanel1layout); jpanel1layout.sethorizontalgroup (jpanel1layout.createParalleGroup (javax.swing.grouplayout.alignment.leading) .addcomponent (jscrollpane1, javax.swing.grouplayout.alignment.trailing, javax.swing.grouplayout.Default_Size, 795 Short.max_value) .AddGroup (jpanel1Layout.CreateSquentialGroup () .Addgap (50, 50, 50) .AddComponent (jpanel2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplay .AddContainergap (173, short.max_value))); jpanel1layout.setVerticalGroup (jpanel1layout.createParalleGroup (javax.swing.grouplayout.alignment.leading) .addgroup (jpanel1layout.createselentialGroup () .Addcomponent (jpanel1lating.createseentialgroup (). javax.swing.grouplayout.preferred_size) .addgap (10, 10, 10) .AddComponent (jpanel2, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value))); javax.swing.grouplayout Layout = new javax.swing.grouplayout (getContentPane ()); getContentPane (). setLayout (Layout); Layout.SethorizontalGroup (Layout.CreateParalleGroup (javax.swing.grouplayout.alignment.leading) .addComponent (jpanel1, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value); Layout.SetVerticalGroup (Layout.CreateParallelGroup (javax.swing.grouplayout.Alignment.Leading) .AddComponent (jpanel1, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value)); paquet(); } // </ editor-fold> // Initialisation des données de table publique void initData () {// Chargement des données defauftAltTableModel dtm = (defaultTableModel) bookTable.getModel (); // Clear Table While (dtm.GetRowCount ()> 0) {dtm.ReMoverow (0); } // Charger les données Set <Integer> set = map.KeySet (); for (Integer i: set) {bookBean bean = map.get (i); Vecteur v = nouveau vecteur (); v.add (bean.getId ()); v.add (bean.getBookName ()); v.add (bean.getBookType ()); v.add (bean.getMoney ()); v.add (bean.getMemo ()); dtm.Addrow (v); }} // Obtenez toutes les catégories de gestion de catégorie public void initType () {set <Integer> set = map1.KeySet (); DefaultComboBoxModel dcm = (defaultComboBoxModel) btype.getModel (); dcm.RemoveAllelements (); for (Integer i: set) {TypeBean bean = map1.get (i); dcm.Addelement (bean.getTyPename ()); }} private void jButton2Actionperformed (java.awt.event.actionEvent evt) {// Enregistrer la fonction // Enregistrer la valeur dans la zone de texte First String id = bid.getText (); String bookName = bname.getText (); String bookType = (String) btype.getSelectedItem (); String memo = bmemo.getText (); String Money = bmoney.getText (); // brodé dans un objet BookBean Bean = new BookBean (); bean.setid (Integer.ParseInt (id)); bean.setBookName (bookname); bean.setBookType (bookType); bean.setmemo (mémo); bean.setmoney (argent); // Mettez le bean dans la carte // map <Integer, TypeBean> map = new HashMap <Integer, typeBean> (); map.put (Integer.Parseint (id), bean); // Mettez la carte dans le fichier bookdao.writebook (carte); // Refresh Table InitData (); } private void jbutton1actionperformed (java.awt.event.actionEvent evt) {// Lorsque ajouté, effacez les informations dans la zone de texte et définissez le numéro de série sur modifiable. bid.setEnabled (true); bid.setText (""); bName.setText (""); BTYPE.SETSELECTEDITEM (""); BMEMO.SETTEXT (""); bmoney.settext (""); } private void bookTableMousEClicked (java.awt.event.mousevent evt) {// obtenir le numéro de ligne sélectionné et le numéro de série int currentrow = bookTable.getSelectedRow (); // bookBean bean = map.get (currentrow); // Affiche la ligne sélectionnée à la barre d'information Bid.seTText ((Integer) bookTable.getValueat (CurrentRow, 0) + ""); BNAME.SETTEXT ((String) bookTable.getValueat (CurrentRow, 1)); BTYPE.SETSELECTEDITEM ((String) bookTable.getValueat (CurrentRow, 2)); bmoney.setText ((String) bookTable.getValueat (currentrow, 3)); BMEMO.SETTEXT ((String) bookTable.getValueat (CurrentRow, 4)); //bMemo.SeTText (bean.getMemo ()); bid.setEnabled (false); //The serial number box cannot be edited} private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // Delete operation// Get the selected row number and serial number int currentRow = bookTable.getSelectedRow(); int id = (Integer)bookTable.getValueAt(currentRow, 0); map.remove(id); bookDao.writeBook(map); JOptionPane.showMessageDialog(this,"Category delete successful"); initData(); } private void btypeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // Update operation// Save the value in the text box first int currentRow = bookTable.getSelectedRow(); int id = (Integer) bookTable.getValueAt(currentRow, 0); String bookName = bname.getText(); String bookType = (String) btype.getSelectedItem(); String memo = bmemo.getText(); String money = bmoney.getText(); //Embroidered into an object BookBean bean = new BookBean(); bean.setId(id); bean.setBookName(bookName); bean.setBookType(bookType); bean.setMemo(memo); bean.setMoney(money); //Put the bean into the map// Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); map.put(id, bean); //Put the map into the file bookDao.writeBook(map); //Refresh table JOptionPane.showMessageDialog(this,"Category update succeeded"); initData(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new BookForm().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JTextField bid; private javax.swing.JTextField bmemo; private javax.swing.JTextField bmoney; private javax.swing.JTextField bname; private javax.swing.JTable bookTable; private javax.swing.JComboBox btype; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; 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.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration }TypeForm.java
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * TypeForm.java * * Created on 2013-2-26, 19:07:51 */ package com.liu.view; import com.liu.dao.TypeDAO; import com.liu.po.TypeBean; import java.util.hashmap; import java.util.Map; import java.util.Set; import java.util.Vector; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; /** * * @author asus */ public class TypeForm extends javax.swing.JFrame { private TypeDAO typeDao; private Map<Integer,TypeBean> map; /** Creates new form TypeForm */ public TypeForm() { initComponents(); typeDao = new TypeDAO(); map = typeDao.readType(); initData(); } /** 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); typeTable = new javax.swing.JTable(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); tid = new javax.swing.JTextField(); tname = new javax.swing.JTextField(); jScrollPane2 = new javax.swing.JScrollPane(); tmemo = new javax.swing.JTextArea(); jButton1 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); setTitle("Type Management"); setBounds(new java.awt.Rectangle(100, 50, 0, 0)); setIconImage(new javax.swing.ImageIcon(getClass().getResource("/com/liu/resouce/logo.jpg")).getImage()); typeTable.setFont(new java.awt.Font("安体", 0, 18)); typeTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null}, {null, null, null}, {null, null, null}, {null, null, null} }, new String [] { "Serial Number", "Category Name", "Remarks" } ) { Class[] types = new Class [] { java.lang.Integer.class, java.lang.String.class, java.lang.String.class }; boolean[] canEdit = new boolean [] { false, false, false }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); typeTable.setColumnSelectionAllowed(true); typeTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { typeTableMouseClicked(evt); } }); typeTable.addContainerListener(new java.awt.event.ContainerAdapter() { public void componentAdded(java.awt.event.ContainerEvent evt) { typeTableComponentAdded(evt); } }); jScrollPane1.setViewportView(typeTable); typeTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); typeTable.getColumnModel().getColumn(0).setResizable(false); typeTable.getColumnModel().getColumn(2).setResizable(false); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Category Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("宋体", 0, 18))); // NOI18N jLabel1.setFont(new java.awt.Font("宋体", 0, 18)); jLabel1.setText("宋体:"); jLabel2.setFont(new java.awt.Font("宋体", 0, 18)); jLabel2.setText("Category name:"); jLabel3.setFont(new java.awt.Font("宋体", 0, 18)); jLabel3.setText("宋体".tid.setFont(new java.awt.Font("宋体", 0, 18)); tid.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { tidActionPerformed(evt); } }); tname.setFont(new java.awt.Font("宋体", 0, 18)); tmemo.setColumns(20); tmemo.setFont(new java.awt.Font("Monospaced", 0, 18)); tmemo.setRows(5); jScrollPane2.setViewportView(tmemo); jButton1.setText("Save"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton3.setText("Update"); jButton3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton3MouseClicked(evt); } }); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setText("Delete"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setText("New"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(39, 39, 39) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(tname, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tid, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE))))) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(70, 70, 70) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(41, 41, 41) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(37, 37, 37) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(20, 20, 20))) .addGap(83, 83, 83)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(31, 31, 31) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(tid, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(27, 27, 27) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(tname, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(45, 45, 45) .addComponent(jLabel3)) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(24, 24, 24) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(35, 35, 35) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)) ); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(66, 66, 66) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(55, Short.MAX_VALUE)) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); paquet(); }// </editor-fold> // Initialization of table data public void initData(){ //Loading data DefaultTableModel dtm = (DefaultTableModel)typeTable.getModel(); //Clear table while(dtm.getRowCount()>0){ dtm.removeRow(0); } //Load data Set<Integer>set = map.keySet(); for(Integer i:set){ TypeBean bean = map.get(i); Vector v = new Vector(); v.add(bean.getId()); v.add(bean.getTypeName()); v.add(bean.getMemo()); dtm.addRow(v); } } private void tidActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //Save type operation//Save the value in the text box first String id = tid.getText(); String typeName = tname.getText(); String memo = tmemo.getText(); //Encapsulate it into an object TypeBean bean = new TypeBean(); bean.setId(Integer.parseInt(id)); bean.setMemo(memo); bean.setTypeName(typeName); //Put the bean into the map// Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); map.put(Integer.parseInt(id), bean); //Put the map into the file typeDao.writeType(map); //Refresh table initData(); } private void typeTableComponentAdded(java.awt.event.ContainerEvent evt) { // TODO add your handling code here: } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // Delete operation// Get the selected row number and sequence number int currentRow = typeTable.getSelectedRow(); int id = (Integer)typeTable.getValueAt(currentRow, 0); map.remove(id); typeDao.writeType(map); JOptionPane.showMessageDialog(this,"Category delete successful"); initData(); } private void jButton3MouseClicked(java.awt.event.MouseEvent evt) { } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // Update operation // Save the value in the text box first int currentRow = typeTable.getSelectedRow(); int id = (Integer) typeTable.getValueAt(currentRow, 0); String typeName = tname.getText(); String memo = tmemo.getText(); // Encapsulate it into an object TypeBean bean = new TypeBean(); bean.setId(id); bean.setMemo(memo); bean.setTypeName(typeName); //Put the bean into the map// Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); map.put(id, bean); //Put the map into the file typeDao.writeType(map); //Refresh table JOptionPane.showMessageDialog(this,"Category update successful"); initData(); } private void typeTableMouseClicked(java.awt.event.MouseEvent evt) { //Get selected line number and serial number int currentRow = typeTable.getSelectedRow(); // Display the selected row in the information bar tid.setText((Integer) typeTable.getValueAt(currentRow, 0)+""); tname.setText((String) typeTable.getValueAt(currentRow, 1)); tmemo.setText((String) typeTable.getValueAt(currentRow, 2)); tid.setEnabled(false); // Serial number box cannot be edited} private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // When added, clear the information in the text box and set the serial number to editable. tid.setEnabled(true); tid.setText(""); tname.setText(""); tmemo.setText(""); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TypeForm().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextField tid; private javax.swing.JTextArea tmemo; private javax.swing.JTextField tname; private javax.swing.JTable typeTable; // End of variables declaration }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.