تشارككم الأمثلة في هذه المقالة في رمز Java المحدد لتنفيذ نظام إدارة المكتبة للرجوع إليه. المحتوى المحدد كما يلي
/* (يبدأ تعليق رأس البرنامج)
* حقوق الطبع والنشر وبيان الإصدار جزء من البرنامج
* حقوق الطبع والنشر (C) 2011 ، كلية علوم الكمبيوتر بجامعة يانتاي
* جميع الحقوق محفوظة.
* اسم الملف: "نظام إدارة الكتب-Java"
* المؤلف: Liu Jiangbo
* تاريخ الانتهاء: 1 مارس 2012
* رقم الإصدار: v3.0
* وصف المهام والحلول
* وصف السؤال:
* نهاية التعليقات على رأس البرنامج
*/
حالة إنشاء حزمة الملف:
bookdao.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. */ package com.liu.dao ؛ استيراد com.liu.po.bookbean ؛ استيراد java.io.*؛ استيراد java.util.hashmap ؛ استيراد java.util.map ؛ استيراد java.util.logging.level ؛ استيراد java.util.logging.logger ؛ / ** * * Author ASUS */ public class bookdao {// اكتب public void writebook (map <integer ، bookbean> bookmap) {// fileOutputStream fos = null ؛ ObjectOutputStream OOS = NULL ؛ حاول {fos = new FileOutputStream ("f: //cache//book.txt") ؛ OOS = new ObjectOutputStream (FOS) ؛ OOS.WriteObject (bookmap) ؛ // مسح ذاكرة التخزين المؤقت oos.flush () ؛ } catch (fileNotFoundException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ }. } أخيرًا {try {// open and closed OOS.Close () ؛ fos.close () ؛ } catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ }}} // اقرأ الخريطة العامة <integer ، bookbean> readbook () {fileInputStream fis = null ؛ ObjectInputStream OIS = NULL ؛ الخريطة <integer ، bookbean> map = null ؛ حاول {fis = new FileInputStream ("f: //cache//book.txt") ؛ OIS = new ObjectInputStream (FIS) ؛ map = (map <integer ، bookbean>) ois.readobject () ؛ // استثناء يحدث ويدخل catch} catch (classnotfoundException ex) {logger.getLogger (typedao.class.getName ()). } catch (fileNotFoundException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ } catch (ioException ex) {//logger.getLogger(typedao.class.getName().LOG(Level.severe ، null ، ex) ؛ //ex.printstacktrace () ؛ map = new hashmap <integer ، bookbean> () ؛ // إنشاء خريطة} أخيرًا {try {if (ois! = null) {ois.close () ؛ } if (fis! = null) {fis.close () ؛ }} catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ }} خريطة الإرجاع ؛ }}typedao.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. */ package com.liu.dao ؛ استيراد com.liu.po.typebean ؛ استيراد java.io.*؛ استيراد java.util.*؛ استيراد java.util.logging.*؛ / **** قراءة وكتابة الملفات*/ الفئة العامة typedao {// اكتب public void writeType (map <integer ، typeBean> typemap) {// fileOutputStream fos = null ؛ ObjectOutputStream OOS = NULL ؛ حاول {fos = new FileOutputStream ("f: //cache//type.txt") ؛ OOS = new ObjectOutputStream (FOS) ؛ OOS.WriteObject (typemap) ؛ // مسح ذاكرة التخزين المؤقت oos.flush () ؛ } catch (fileNotFoundException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ } // مستوى الاستثناء في النهاية (ioException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ } أخيرًا {try {// افتح أولاً ثم أغلق OOS.Close () ؛ fos.close () ؛ } catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ }}} // اقرأ الخريطة العامة <integer ، typeBean> endtype () {fileInputStream fis = null ؛ ObjectInputStream OIS = NULL ؛ الخريطة <integer ، typeBean> map = null ؛ حاول {fis = جديد fileInputStream ("f: //cache//type.txt") ؛ OIS = new ObjectInputStream (FIS) ؛ map = (map <integer ، typeBean>) ois.readobject () ؛ // استثناء يحدث ويدخل catch} catch (classnotfoundException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ } catch (fileNotFoundException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ } catch (ioException ex) {//logger.getLogger(typedao.class.getName().LOG(Level.severe ، null ، ex) ؛ //ex.printstacktrace () ؛ map = new hashmap <integer ، typeBean> () ؛ // إنشاء خريطة} أخيرًا {try {if (ois! = null) {ois.close () ؛ } if (fis! = null) {fis.close () ؛ }} catch (ioException ex) {logger.getLogger (typedao.class.getName ()). log (level.severe ، null ، ex) ؛ }} خريطة الإرجاع ؛ }}}bookbean.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. */ package com.liu.po ؛ استيراد java.io.serializable ؛ / ** * * Author ASUS */ Public Class Bookbean تنفذ Serializable {private int id ؛ اسم سلسلة خاصة سلسلة خاصة booktype ؛ مذكرة سلسلة خاصة سلسلة خاصة / ** * regurn المعرف */ public int getId () {return id ؛ } / ** * param id المعرف لتعيين * / public void setId (int id) {this.id = id ؛ } / ** * return اسم BookName * / public String getBookName () {return bookName ؛ } / ** * param bookName اسم BookName لتعيين * / public void setBookName (string bookName) {this.bookName = bookName ؛ } / ** * return the booktype * / public string getBookType () {return booktype ؛ } / ** * param booktype the booktype لتعيين * / public void setBookType (String booktype) {this.booktype = booktype ؛ } / ** * regurn the memo * / public string getMemo () {return memo ؛ } / ** * param memo المذكرة لتعيين * / public void setMemo (memo string) {this.memo = memo ؛ } / ** * return money * / public string getMoney () {return money ؛ } / ** * param money الأموال لتعيين * / public void setMoney (string money) {this.money = money ؛ }}typebean.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. */ package com.liu.po ؛ / ** * * Author Asus */ import java.io.serializable ؛ الطبقة العامة typebean تنفذ التسلسل {private int id ؛ سلسلة typename الخاصة ؛ مذكرة سلسلة خاصة / ** * regurn المعرف */ public int getId () {return id ؛ } / ** * param id المعرف لتعيين * / public void setId (int id) {this.id = id ؛ } / ** * return typename * / public string getTyPename () {return typename ؛ } / ** * param typename typename لتعيين * / public void setTyPename (سلسلة typename) {this.typename = typename ؛ } / ** * regurn the memo * / public string getMemo () {return memo ؛ } / ** * param memo المذكرة لتعيين * / public void setMemo (memo string) {this.memo = memo ؛ }}loginform.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. *// * * loginform.java * * تم إنشاؤه في 2013-2-26 ، 18:33:36 */ package com.liu.view ؛ استيراد java.awt.event.keyadapter ؛ استيراد java.awt.event.keyevent ؛ استيراد javax.swing.joptionpane ؛ / ** * * Author ASUS */ loginform public class يمتد javax.swing.jframe {/ ** إنشاء نموذج جديد loginform */ public loginform () {initComponents () ؛ } /** هذه الطريقة تسمى من داخل المنشئ إلى* تهيئة النموذج. * تحذير: لا تعدل هذا الرمز. يتم تجديد محتوى هذه الطريقة دائمًا بواسطة محرر النماذج. */ suppressWarnings ("Unchecked") // <Editor-Fold DefaultState = "Glapsed" desc = "code code"> 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 ("واجهة تسجيل الدخول") ؛ 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.keyevent evt) {formkeypression (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 ("اسم المستخدم:") ؛ JLabel3.setFont (New Java.awt.font ("宋体" ، 0 ، 24)) ؛ jlabel3.settext ("كلمة المرور:") ؛ logInname.setName ("") ؛ . loginname.addkeylistener (new java.awt.event.keyadapter () {public void keypressed (java.awt.event.keyevent evt) {loginnamekeypression (evt) ؛}}) ؛ loginpwd.addkeylistener (new java.awt.event.keyadapter () {public void keypressed (java.awt.event.keyevent evt) {loginpwDkeyPression (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 التصميم = new javax.swing.grouplayout (getContentPane ()) ؛ getContentPane (). setLayout (التصميم) ؛ Skyout.SethorizontalGroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addgroup (layout.createsequentialgroup () .addgap (97 ، 97 ، .addcomponent (JLabel2) .addComponent (JLabel3)) .addpreferredgap (javax.swing.layoutstyle.componentplication.unreled) .addgroup (layout.createparalleglgroup (javax.swing.grouplayout.alignment.addoment ، passdcomponed). .addComponent (loginName ، javax.swing.grouplayout.default_size ، 215 ، mort.max_value) Short.max_value) .addcomponent (JLabel1 ، javax.swing.grouplayout.preferred_size ، 263 ، javax.swing.grouplayout.preferred_size) .addgap (113 ، 113 ، 113). reghout.createsequentialgroup () .addContainerGap (299 ، Short.max_value) .AdComponent (jbutton1 ، javax.swing.grouplayout.preferred_size ، 97 ، javax.swing.grouplayout.predred_size) .adddgap (110 ، 110 ، 110 ، 110) ؛ Synout.setverticalGroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addgroup (layout.createsequentialgroup () .addgap (50 ، 50 ، 50) .addComponent (jlabel1 ، javax.swing.groplayout.prefered. javax.swing.grouplayout.preferred_size) .Addgap (38 ، 38 ، 38) .addgroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.baseline) .addComponent (jlabel2) .addcomponent (loginname ، javax.swing.grouplayout.preferred_size ، 29 ، javax.swing.grouplayout.preferred_size)) .addgap (26 ، 26 ، 26) .addgroup .addComponent (loginpwd ، javax.swing.grouplayout.preferred_size ، 29 ، javax.swing.grouplayout.preferred_size)) .addgap (18 ، 18 ، 18). javax.swing.grouplayout.preferred_size) .AddContainerGap (21 ، Short.max_value))) ؛ علية()؛ } // </editor-fold> private void loginnameActionPerformed (java.awt.event.actionevent evt) {// todo أضف رمز التعامل هنا:} private void jbutton1ActionPerformed ( احصل على اسم المستخدم وكلمة المرور اسم السلسلة الأولى = loginName.getText () ؛ سلسلة كلمة مرور = سلسلة جديدة (logInPWD.GetPassword ()) ؛ // 2. تحقق من ("admin" .equals (name) && "admin" .equals (password)) {// login بنجاح // إخفاء loginform وأظهر mainform this.setVisible (false) ؛ new Mainform (). setVisible (true) ؛ } آخر {// فشل تسجيل الدخول joptionpane.showmessagedialog (هذا ، "اسم المستخدم أو كلمة المرور!") ؛ }}} private void formkeypression (java.awt.event.keyevent evt) {// اضغط على لوحة المفاتيح إلى تسجيل الدخول} private void loginnamekeypression (java.awt.event.keyevent evt) {// اضغط على لوحة المفاتيح لتسجيل الدخول إذا (evt.getxtext. jbutton1.doclick () ؛ }} private void loginpwDkeyPression (java.awt.event.keyevent evt) {// اضغط على لوحة المفاتيح لتسجيل الدخول إذا (evt.getKeytext (evt.getKeyCode ()). المقارنة }} / ** * param args وسيطات سطر الأوامر * / public static void main (string args []) {java.awt.eventqueue.invokelater (new RunNable () {public void run () {new loginform (). setVisible (true) ؛}) ؛ } // إعلان المتغيرات - لا تعدل javax.swing.jtextfield loginname ؛ الخاص javax.swing.jpasswordfield loginpwd ؛ الخاص javax.swing.jbutton jbutton1 ؛ الخاص javax.swing.jlabel jlabel1 ؛ الخاص javax.swing.jlabel jlabel2 ؛ الخاص javax.swing.jlabel jlabel3 ؛ // نهاية الإعلان المتغير}Mainform.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. *// * * mainform.java * * تم إنشاؤه في 2013-2-26 ، 18:35:25 */ package com.liu.view ؛ / ** * * Author Asus */ Class Mainform يمتد Javax.swing.jframe {/ ** إنشاء نموذج جديد Mainform */ Public Mainform () {initComponents () ؛ } /** هذه الطريقة تسمى من داخل المنشئ إلى* تهيئة النموذج. * تحذير: لا تعدل هذا الرمز. يتم تجديد محتوى هذه الطريقة دائمًا بواسطة محرر النماذج. */ suppressWarnings ("Unchecked") // <Editor-Fold DefaultState = "Glapsed" desc = "code code"> private void initComponents () {jlabel1 = new javax.swing.jlabel () ؛ jpanel1 = new javax.swing.jpanel () ؛ jlabel2 = new javax.swing.jlabel () ؛ jmenubar1 = new javax.swing.jmenubar () ؛ إدارة التكوين = new javax.swing.jmenuitem1 = new javax.swing.jmenuitem () ؛ jmenuitem2 = new javax.swing.jmenuitem () ؛ jmenu2 = new javax.swing.jmenuitem () ؛ jmenuitem3 = new javax.swing.jmenuitem () ؛ setDefaultCloseOperation (javax.swing.windowconstants.exit_on_close) ؛ Settitle ("نظام إدارة الكتب") ؛ 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 ("مرحبًا بك لاستخدام نظام إدارة الاقتراض") ؛ javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout (jpanel1) ؛ jpanel1.setLayout (jpanel1layout) ؛ jpanel1layout.sethorizontalgroup (jpanel1layout.createparallelgroup (javax.swing.grouplayout.alignment.leading). Short.max_value)) ؛ jpanel1layout.setverticalgroup (jpanel1layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addgroup (javax.swing.grouplayout.alignment.trailing ، jpanel1layout.createSequentialgroup (). javax.swing.grouplayout.default_size ، 78 ، Short.max_value))) ؛ Configuration Management.settext ("إدارة التكوين") ؛ jmenuitem1.setaccelerator (javax.swing.keysstroke.getkeysstroke (java.awt.event.keyevent.vk_l ، java.awt.event.inputevent.ctrl_mask)) ؛ jmenuitem1.settext ("إدارة الفئة") ؛ 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.keysstroke.getkeysstroke (java.awt.event.keyevent.vk_t ، java.awt.event.inputevent.ctrl_mask)) ؛ jmenuitem2.settext ("إدارة الكتاب") ؛ jmenuitem2.AddActionListener (new java.awt.event.actionListener () {public void actionperformed (java.awt.event.actionevent evt) {jmenuitem2ActionPerformed (evt) ؛}}) ؛ Configuration Management.Add (jmenuitem2) ؛ jmenubar1.Add (إدارة التكوين) ؛ jmenu2.settext ("الاقتراض") ؛ jmenuitem4.setaccelerator (javax.swing.keysstroke.getkeysstroke (java.awt.event.keyevent.vk_j ، java.awt.event.inputevent.ctrl_mask)) ؛ jmenuitem4.settext ("عقد الإيجار") ؛ jmenu2.add (jmenuitem4) ؛ jmenubar1.add (jmenu2) ؛ jmenu1.settext ("العودة إلى الكتاب") ؛ jmenuitem3.setaccelerator (javax.swing.keysstroke.getkeysstroke (java.awt.event.keyevent.vk_h ، java.awt.event.inputevent.ctrl_mask)) ؛ jmenuitem3.settext ("العودة إلى الكتاب") ؛ jmenu1.add (jmenuitem3) ؛ jmenubar1.add (jmenu1) ؛ setjmenubar (jmenubar1) ؛ javax.swing.grouplayout التصميم = new javax.swing.grouplayout (getContentPane ()) ؛ getContentPane (). setLayout (التصميم) ؛ Skyout.SethorizontalGroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .AdComponent (jlabel1 ، 0 ، 0 ، short.max_value) .addgroup (layout.createsequentiblegroup. javax.swing.grouplayout.default_size ، javax.swing.grouplayout.default_size ، short.max_value) .addcontainergap ())) ؛ Synout.setverticalGroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addgroup (javax.swing.grouplayout.alignment.trailing ، layout.createsequentialgroup () .addcontainergap () .addcomponent (jpanel1 ، javax.swing.grouplayout.default_size ، javax.swing.grouplayout.default_size ، short.max_value) .addpreferredgap (javax.swing.layoutstyle.componentponmance.relex) .addComponent javax.swing.grouplayout.preferred_size))) ؛ علية()؛ } // </editor-fold> private void jmenuitem1ActionPerformed (java.awt.event.actionevent evt) {// type management typeform (). setVisible (true) ؛ } private void jmenuitem2ActionPerformed (java.awt.event.actionevent evt) {// book management bookform (). setVisible (true) ؛ } / ** * param args وسيطات سطر الأوامر * / public static void main (string args []) {java.awt.eventqueue.invokelater (new RunNable () {public void run () {new mainform (). setVisible (true) ؛}}) ؛ } // إعلان المتغيرات - لا تعدل javax.swing.jlabel jlabel1 ؛ الخاص javax.swing.jlabel jlabel2 ؛ الخاص javax.swing.jmenu jmenu1 ؛ الخاص javax.swing.jmenuitem jmenuitem2 ؛ الخاص javax.swing.jmenuitem jmenuitem2 ؛ الخاص javax.swing.jmenuitem jmenuitem3 ؛ الخاص javax.swing.jmenuitem jmenuitem3 ؛ الخاص javax.swing.jmenuitem jmenuitem4 ؛ الخاص javax.swing.jpanel jpanel1 ؛ Private Javax.swing.jmenu إدارة التكوين ؛ // نهاية إعلان المتغيرات}bookform.java
/ * * لتغيير هذا القالب ، اختر الأدوات | قوالب * وفتح القالب في المحرر. *// * * bookform.java * * تم إنشاؤه في 2013-2-28 ، 8:23:01 */ package com.liu.view ؛ استيراد com.liu.dao.bookdao ؛ استيراد com.liu.dao.typledao ؛ استيراد com.liu.po.bookbean ؛ استيراد com.liu.po.typebean ؛ استيراد java.util.map ؛ استيراد java.util.set ؛ استيراد java.util.vector ؛ استيراد javax.swing.defaultComboboxModel ؛ استيراد javax.swing.joptionpane ؛ استيراد javax.swing.table.defaultTableModel ؛ / ** * * Author ASUS */ Public Class Bookform يمتد javax.swing.jframe {/ ** إنشاء نموذج جديد bookform */ private map <integer ، bookbean> map ؛ خريطة خاصة <integer ، typeBean> map1 ؛ Bookdao Bookdao ؛ Typedao typedao الخاص ؛ public bookform () {initComponents () ؛ bookdao = new bookdao () ؛ typedao = new typedao () ؛ الخريطة = bookdao.readbook () ؛ map1 = typedao.readtype () ؛ initType () ؛ initData () ؛ } /** هذه الطريقة تسمى من داخل المنشئ إلى* تهيئة النموذج. * تحذير: لا تعدل هذا الرمز. يتم تجديد محتوى هذه الطريقة دائمًا بواسطة محرر النماذج. */ suppressWarnings ("Unchecked") // <Editor-Fold DefaultState = "Glapsed" desc = "code code"> 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 () ؛ Settitle ("إدارة الكتاب") ؛ 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)) ؛ . null ، null} ، {null ، null ، null ، null ، null ، null ، null} ، {null ، null ، null ، null ، null ، null} ، {null ، null ، null ، null ، null ، null ، "نوع الكتاب" ، "الإيجار" ، "الملاحظات"}) {class [] class [] {java.lang.integer.class ، java.lang.string.class ، java.lang.string.class ، java.lang.class ، java.lang.clstring.class} ؛ False ، False ، False} ؛ booktable.addmouselistener (new java.awt.event.mouseadapter () {public void mouseclicked (java.awt.event.mouseevent evt) {booktablemouseclicked (evt) ؛}}) ؛ jscrollpane1.setViewPortView (booktable) ؛ jpanel2.setBorder (javax.swing.borderfactory.createTitledBorder (null ، "التفاصيل" ، javax.swing.border.titledborder.default_justific // noi18n bmemo.setfont (new java.awt.font ("宋体" ، 0 ، 18)) ؛ jbutton1.settext ("new") ؛ 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 ("تحديث") ؛ 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 (سلسلة جديدة [] {"الأدب" ، "التعليم" ، "التكنولوجيا" ، "الأدب"})) ؛ 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 ("الإيجار:") ؛ javax.swing.grouplayout jpanel2layout = new javax.swing.grouplayout (jpanel2) ؛ jpanel2.setLayout (jpanel2layout) ؛ jpanel2layout.sethorizontalgroup (jpanel2layout.createparaldgroup (javax.swing.grouplayout.alignment.Leading). .addgroup (jpanel2layout.createparalleglgroup (javax.swing.grouplayout.alignment.Leading) .addgroup (jpanel2layout.createsequentialgroup .addComponent (JLabel2 ، javax.swing.grouplayout.default_size ، 83 ، mort.max_value) .addgroup (jpanel2layout.createparaldgroup (jlabel3). .addcomponent (jlabel4))) .addpreferredgap (javax.swing.layoutstyle.componentplicate.reled)) .addgroup (jpanel2layout.createsequentialgroup () .addcomponent (jlabel1) .addgap (33 ، 33 ، 33)))))). .addgroup (jpanel2layout.createparalleglgroup (javax.swing.grouplayout.alignment.leading) .addcomponent (bmemo ، javax.swing.grouplayout.default_size ، 375 ، mort.max_value). 375 ، Short.max_value) .addcomponent (Bmoney ، javax.swing.grouplayout.default_size ، 375 ، mort.max_value) .addcomponent (bmoney ، javax.swing.grouplayout.default_size ، 375 ، max_value). javax.swing.grouplayout.default_size ، 375 ، Short.max_value) .addgroup (jpanel2layout.createsequentialgroup () .AdComponent (jbutton1 ، javax.swing.grouplayout.preferred_size ، 73 ، javax.swing. .addgap (28 ، 28 ، 28) .AdComponent (jbutton2 ، javax.swing.grouplayout.preferred_size ، 69 ، javax.swing.grouplayout.preferred_size) .addgap (30 ، 30 ، 30). 73 ، javax.swing.grouplayout.preferred_size) .addpreferredgap (javax.swing.layoutstyle.componentplication.reled ، 28 ، quon javax.swing.grouplayout.preferred_size). jpanel2layout.setverticalgroup (jpanel2layout.createparallelgroup (javax.swing.grouplayout.alignment.leading). .addgroup (jpanel2layout.createparaldalgroup (javax.swing.grouplayout.alignment.baseline) .addcomponent (jlabel1 ، javax.swing.grouplayout.preferred_size ، 25 ، javax.swing.grouplayout.preferred_size). javax.swing.grouplayout.preferred_size ، 37 ، javax.swing.grouplayout.preferred_size)) .addgap (13 ، 13 ، 13) .addgroup .addcomponent (bname ، javax.swing.grouplayout.preferred_size ، 37 ، javax.swing.grouplayout.preferred_size) .addgap (18 ، 18 ، 18) .addgroup ( .addcomponent (jlabel3) .addcomponent (Btype ، javax.swing.grouplayout.preferred_size ، 30 ، javax.swing.grouplayout.preferred_size)) .addgap (26 ، 26 ، 26) .addgroup (jpanel2layout.createparaldalgroup (javax.swing.grouplayout.alignment.baseline) .addcomponent (jlabel5) .addcomponent (bmoney ، javax.swing.grouplayout.preferred_size ، 35 ، javax.swing. .addgap (32 ، 32 ، 32) .addgroup (jpanel2layout.createparaldgroup (javax.swing.grouplayout.alignment.Leading). javax.swing.grouplayout.preferred_size) .addgap (64 ، 64 ، 64) .addgroup (jpanel2layout.createparaldgroup (javax.swing.grouplayout.alignment.baseline) .addComponent (jbutton1 ، javax.swing.grouplayout.preferred_size) .addcomponent (jbutton2 ، javax.swing.grouplayout.preferred_size ، 32 ، javax.swing.grouplayout.preferred_size) .addComponent (jbutton3 ، javax.swing.proudridd_size. javax.swing.grouplayout.preferred_size) .addcomponent (jbutton4 ، javax.swing.grouplayout.preferred_size ، 32 ، javax.swing.grouplayout.preferred_size)). javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout (jpanel1) ؛ jpanel1.setLayout (jpanel1layout) ؛ jpanel1layout.sethorizontalgroup (jpanel1layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addcomponent (jscrollpane1 ، javax.swing.grouplayout.alignment.trailing ، javax.swing.default Short.max_value) .addgroup (jpanel1layout.createsequentialgroup () .addgap (50 ، 50 ، 50) .AdComponent (jpanel2 ، javax.swing.grouplayout.preferred_size ، javax.swing.grouplayout.default_size ، javax.swing.grouplayout.preferred_size) .addContainerGap (173 ، Short.max_value))) ؛ jpanel1layout.setverticalgroup (jpanel1layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addgroup (jpanel1layout.createsequentialgroup () .addcomponent (jscrollpane1 ، javax.swing.prefered. javax.swing.grouplayout.preferred_size) .addgap (10 ، 10 ، 10) .AdComponent (jpanel2 ، javax.swing.grouplayout.default_size ، javax.swing.grouplayout.default_size ، short.max_value)))) ؛ javax.swing.grouplayout التصميم = new javax.swing.grouplayout (getContentPane ()) ؛ getContentPane (). setLayout (التصميم) ؛ Layout.SethorizontalGroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addcomponent (jpanel1 ، javax.swing.grouplayout.default_size ، javax.swing.grouplayout.default_size ، Synout.setverticalGroup (layout.createparallelgroup (javax.swing.grouplayout.alignment.leading) .addcomponent (jpanel1 ، javax.swing.grouplayout.default_size ، javax.swing.grouplayout.default_size ، stors.max_value) ؛ علية()؛ } // </editor-fold> // تهيئة بيانات الجدول public void initData () {// تحميل البيانات defaultTableModel dtm = (defaultTableModel) booktable.getModel () ؛ // clear table بينما (dtm.getRowCount ()> 0) {dtm.removerow (0) ؛ } // تحميل مجموعة البيانات <integer> set = map.keyset () ؛ لـ (integer i: set) {bookbean bean = map.get (i) ؛ ناقل V = جديد ناقل () ؛ V.Add (Bean.getId ()) ؛ V.Add (Bean.getBookName ()) ؛ V.Add (Bean.getBookType ()) ؛ V.Add (Bean.getMoney ()) ؛ V.Add (Bean.getMemo ()) ؛ dtm.addrow (V) ؛ }} // احصل على جميع فئات إدارة الفئات public void inittype () {set <integer> set = map1.keyset () ؛ DefaultComboboxModel DCM = (DefaultComboboxModel) btype.getModel () ؛ dcm.removeAllements () ؛ لـ (integer i: set) {typebean bean = map1.get (i) ؛ dcm.addelement (bean.gettypename ()) ؛ }} private void jbutton2ActionPerformed (java.awt.event.actionevent evt) {// حفظ الدالة // حفظ القيمة في مربع النص المعرف الأول = bid.getText () ؛ string bookName = bname.getText () ؛ String booktype = (string) btype.getSelectedItem () ؛ memo string = bmemo.getText () ؛ سلسلة الأموال = bmoney.getText () ؛ // المطرزة في كائن bookbean bean = new bookbean () ؛ Bean.setId (integer.parseint (id)) ؛ Bean.setBookName (BookName) ؛ bean.setbooktype (booktype) ؛ Bean.setmemo (مذكرة) ؛ Bean.setMoney (المال) ؛ // ضع الفول في الخريطة // الخريطة <integer ، typeBean> map = new hashmap <integer ، typeBean> () ؛ map.put (integer.parseint (id) ، Bean) ؛ // ضع الخريطة في ملف pookdao.writebook (MAP) ؛ // تحديث جدول initData () ؛ } private void jbutton1ActionPerformed (java.awt.event.actionevent evt) {// عند إضافتها ، قم بمسح المعلومات الموجودة في مربع النص وقم بتعيين الرقم التسلسلي على قابلة للتحرير. bid.setEnabled (true) ؛ bid.settext ("") ؛ bname.settext ("") ؛ btype.SetSelectedItem ("") ؛ bmemo.settext ("") ؛ bmoney.settext ("") ؛ } private void booktableMouseClicked (java.awt.event.mouseevent evt) {// الحصول على رقم سطر محدد ورقم متسلسل int currentRow = booktable.getSelectedRow () ؛ // bookbean bean = map.get (currentRow) ؛ // إظهار السطر المحدد إلى شريط المعلومات 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; استيراد 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)) ); علية()؛ }// </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 }ما سبق هو كل محتوى هذه المقالة. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.