图书管理系统——java》

图书管理系统——java》

  16687人阅读  评论(73)  收藏  举报
  分类:
 

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:    《图书管理系统——Java》                          
* 作    者:       刘江波                       
* 完成日期:    2012     年  3     月     1   日
* 版 本 号:    v3.0     

* 对任务及求解方法的描述部分 
* 问题描述:  
* 程序头部的注释结束
*/

文件包的建立情况:

 

BookDao.java

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. package com.liu.dao;  
  7.   
  8. import com.liu.po.BookBean;  
  9. import java.io.*;  
  10. import java.util.HashMap;  
  11. import java.util.Map;  
  12. import java.util.logging.Level;  
  13. import java.util.logging.Logger;  
  14.   
  15. /** 
  16.  * 
  17.  * @author asus 
  18.  */  
  19. public class BookDAO {  
  20.      // 写  
  21.     public void writeBook(Map<Integer,BookBean >bookMap){  
  22.      //  
  23.         FileOutputStream fos = null;  
  24.         ObjectOutputStream oos = null;  
  25.         try {  
  26.             fos = new FileOutputStream("F:\\缓存区\\book.txt");  
  27.             oos = new ObjectOutputStream(fos);  
  28.             oos.writeObject(bookMap);  
  29.             //清空缓存区  
  30.             oos.flush();  
  31.         }  
  32.         catch (FileNotFoundException ex) {  
  33.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  34.         }  
  35.         //异常级别高的在后边  
  36.         catch (IOException ex) {  
  37.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  38.         }  
  39.         finally{  
  40.             try{  
  41.                 //先开后闭  
  42.                  oos.close();  
  43.                  fos.close();  
  44.             }catch(IOException ex){  
  45.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE,null,ex);  
  46.             }  
  47.         }  
  48.     }  
  49.   
  50.     //读  
  51.     public Map<Integer,BookBean>readBook(){  
  52.         FileInputStream fis = null;  
  53.         ObjectInputStream ois = null;  
  54.         Map<Integer, BookBean> map = null;  
  55.         try {  
  56.             fis = new FileInputStream("F:\\缓存区\\book.txt");  
  57.             ois = new ObjectInputStream(fis);  
  58.             map = (Map<Integer, BookBean>) ois.readObject();//出现异常进入catch  
  59.         } catch (ClassNotFoundException ex) {  
  60.             Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  61.         } catch (FileNotFoundException ex) {  
  62.             Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  63.         } catch (IOException ex) {  
  64.             //Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  65.             //ex.printStackTrace();  
  66.             map=new HashMap<Integer,BookBean>();//出现异常时,进行创建map  
  67.         } finally{  
  68.             try {  
  69.                 if(ois!=null){  
  70.                     ois.close();  
  71.                 }  
  72.                 if(fis!=null){  
  73.                      fis.close();  
  74.                 }  
  75.   
  76.             } catch (IOException ex) {  
  77.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  78.             }  
  79.         }  
  80.         return map;  
  81.     }  
  82. }  


 

TypeDao.java

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. package com.liu.dao;  
  7.   
  8. import com.liu.po.TypeBean;  
  9. import java.io.*;  
  10. import java.util.*;  
  11. import java.util.logging.*;  
  12. /** 
  13.  * 
  14.  * 对文件进行读和写操作 
  15.  */  
  16. public class TypeDAO {  
  17.   
  18.     // 写   
  19.     public void writeType(Map<Integer,TypeBean >typeMap){  
  20.      //   
  21.         FileOutputStream fos = null;  
  22.         ObjectOutputStream oos = null;  
  23.         try {  
  24.             fos = new FileOutputStream("F:\\缓存区\\type.txt");  
  25.             oos = new ObjectOutputStream(fos);  
  26.             oos.writeObject(typeMap);  
  27.             //清空缓存区  
  28.             oos.flush();  
  29.         }  
  30.         catch (FileNotFoundException ex) {  
  31.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  32.         }  
  33.         //异常级别高的在后边  
  34.         catch (IOException ex) {  
  35.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  36.         }  
  37.         finally{  
  38.             try{  
  39.                 //先开后闭  
  40.                  oos.close();  
  41.                  fos.close();  
  42.             }catch(IOException ex){  
  43.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE,null,ex);  
  44.             }  
  45.         }    
  46.     }  
  47.       
  48.     //读  
  49.     public Map<Integer,TypeBean>readType(){  
  50.         FileInputStream fis = null;  
  51.         ObjectInputStream ois = null;  
  52.         Map<Integer, TypeBean> map = null;  
  53.         try {  
  54.             fis = new FileInputStream("F:\\缓存区\\type.txt");  
  55.             ois = new ObjectInputStream(fis);  
  56.             map = (Map<Integer, TypeBean>) ois.readObject();//出现异常进入catch  
  57.         } catch (ClassNotFoundException ex) {  
  58.             Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  59.         } catch (FileNotFoundException ex) {  
  60.             Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  61.         } catch (IOException ex) {  
  62.             //Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  63.             //ex.printStackTrace();  
  64.             map=new HashMap<Integer,TypeBean>();//出现异常时,进行创建map  
  65.         } finally{  
  66.             try {  
  67.                 if(ois!=null){  
  68.                     ois.close();  
  69.                 }  
  70.                 if(fis!=null){  
  71.                      fis.close();  
  72.                 }  
  73.                  
  74.             } catch (IOException ex) {  
  75.                 Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex);  
  76.             }  
  77.         }  
  78.         return map;  
  79.     }  
  80. }  


 

 

 

BookBean.java

 

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. package com.liu.po;  
  7.   
  8. import java.io.Serializable;  
  9.   
  10. /** 
  11.  * 
  12.  * @author asus 
  13.  */  
  14. public class BookBean implements Serializable{  
  15.   
  16.     private int id;  
  17.     private String bookName;  
  18.     private String bookType;  
  19.     private String memo;  
  20.     private String money;  
  21.   
  22.     /** 
  23.      * @return the id 
  24.      */  
  25.     public int getId() {  
  26.         return id;  
  27.     }  
  28.   
  29.     /** 
  30.      * @param id the id to set 
  31.      */  
  32.     public void setId(int id) {  
  33.         this.id = id;  
  34.     }  
  35.   
  36.     /** 
  37.      * @return the bookName 
  38.      */  
  39.     public String getBookName() {  
  40.         return bookName;  
  41.     }  
  42.   
  43.     /** 
  44.      * @param bookName the bookName to set 
  45.      */  
  46.     public void setBookName(String bookName) {  
  47.         this.bookName = bookName;  
  48.     }  
  49.   
  50.     /** 
  51.      * @return the bookType 
  52.      */  
  53.     public String getBookType() {  
  54.         return bookType;  
  55.     }  
  56.   
  57.     /** 
  58.      * @param bookType the bookType to set 
  59.      */  
  60.     public void setBookType(String bookType) {  
  61.         this.bookType = bookType;  
  62.     }  
  63.   
  64.     /** 
  65.      * @return the memo 
  66.      */  
  67.     public String getMemo() {  
  68.         return memo;  
  69.     }  
  70.   
  71.     /** 
  72.      * @param memo the memo to set 
  73.      */  
  74.     public void setMemo(String memo) {  
  75.         this.memo = memo;  
  76.     }  
  77.   
  78.     /** 
  79.      * @return the money 
  80.      */  
  81.     public String getMoney() {  
  82.         return money;  
  83.     }  
  84.   
  85.     /** 
  86.      * @param money the money to set 
  87.      */  
  88.     public void setMoney(String money) {  
  89.         this.money = money;  
  90.     }  
  91. }  


 

 

 

TypeBean.java

 

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. package com.liu.po;  
  7.   
  8. /** 
  9.  * 
  10.  * @author asus 
  11.  */  
  12. import java.io.Serializable;  
  13.   
  14. public class TypeBean implements Serializable{  
  15.   
  16.     private int id;  
  17.     private String typeName;  
  18.     private String memo;  
  19.   
  20.     /** 
  21.      * @return the id 
  22.      */  
  23.     public int getId() {  
  24.         return id;  
  25.     }  
  26.   
  27.     /** 
  28.      * @param id the id to set 
  29.      */  
  30.     public void setId(int id) {  
  31.         this.id = id;  
  32.     }  
  33.   
  34.     /** 
  35.      * @return the typeName 
  36.      */  
  37.     public String getTypeName() {  
  38.         return typeName;  
  39.     }  
  40.   
  41.     /** 
  42.      * @param typeName the typeName to set 
  43.      */  
  44.     public void setTypeName(String typeName) {  
  45.         this.typeName = typeName;  
  46.     }  
  47.   
  48.     /** 
  49.      * @return the memo 
  50.      */  
  51.     public String getMemo() {  
  52.         return memo;  
  53.     }  
  54.   
  55.     /** 
  56.      * @param memo the memo to set 
  57.      */  
  58.     public void setMemo(String memo) {  
  59.         this.memo = memo;  
  60.     }  
  61.   
  62.       
  63. }  


 

 

LoginForm.java

 

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. /* 
  7.  * LoginForm.java 
  8.  * 
  9.  * Created on 2013-2-26, 18:33:36 
  10.  */  
  11.   
  12. package com.liu.view;  
  13.   
  14. import java.awt.event.KeyAdapter;  
  15. import java.awt.event.KeyEvent;  
  16. import javax.swing.JOptionPane;  
  17.   
  18. /** 
  19.  * 
  20.  * @author asus 
  21.  */  
  22. public class LoginForm extends javax.swing.JFrame {  
  23.   
  24.     /** Creates new form LoginForm */  
  25.     public LoginForm() {  
  26.         initComponents();     
  27.  }  
  28.   
  29.     /** This method is called from within the constructor to 
  30.      * initialize the form. 
  31.      * WARNING: Do NOT modify this code. The content of this method is 
  32.      * always regenerated by the Form Editor. 
  33.      */  
  34.     @SuppressWarnings("unchecked")  
  35.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                            
  36.     private void initComponents() {  
  37.   
  38.         jLabel1 = new javax.swing.JLabel();  
  39.         jLabel2 = new javax.swing.JLabel();  
  40.         jLabel3 = new javax.swing.JLabel();  
  41.         LoginName = new javax.swing.JTextField();  
  42.         LoginPwd = new javax.swing.JPasswordField();  
  43.         jButton1 = new javax.swing.JButton();  
  44.   
  45.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
  46.         setTitle("登陆界面");  
  47.         setBounds(new java.awt.Rectangle(30020000));  
  48.         setIconImage(new javax.swing.ImageIcon(getClass().getResource("/com/liu/resouce/logo.jpg")).getImage());  
  49.         addKeyListener(new java.awt.event.KeyAdapter() {  
  50.             public void keyPressed(java.awt.event.KeyEvent evt) {  
  51.                 formKeyPressed(evt);  
  52.             }  
  53.         });  
  54.   
  55.         jLabel1.setFont(new java.awt.Font("宋体"036));  
  56.         jLabel1.setForeground(new java.awt.Color(20400));  
  57.         jLabel1.setText("图书管理系统");  
  58.   
  59.         jLabel2.setFont(new java.awt.Font("宋体"024));  
  60.         jLabel2.setText("用户名:");  
  61.   
  62.         jLabel3.setFont(new java.awt.Font("宋体"024));  
  63.         jLabel3.setText("密码:");  
  64.   
  65.         LoginName.setName(""); // NOI18N  
  66.         LoginName.addActionListener(new java.awt.event.ActionListener() {  
  67.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  68.                 LoginNameActionPerformed(evt);  
  69.             }  
  70.         });  
  71.         LoginName.addKeyListener(new java.awt.event.KeyAdapter() {  
  72.             public void keyPressed(java.awt.event.KeyEvent evt) {  
  73.                 LoginNameKeyPressed(evt);  
  74.             }  
  75.         });  
  76.   
  77.         LoginPwd.addKeyListener(new java.awt.event.KeyAdapter() {  
  78.             public void keyPressed(java.awt.event.KeyEvent evt) {  
  79.                 LoginPwdKeyPressed(evt);  
  80.             }  
  81.         });  
  82.   
  83.         jButton1.setFont(new java.awt.Font("宋体"024)); // NOI18N  
  84.         jButton1.setText("登录");  
  85.         jButton1.addActionListener(new java.awt.event.ActionListener() {  
  86.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  87.                 jButton1ActionPerformed(evt);  
  88.             }  
  89.         });  
  90.   
  91.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
  92.         getContentPane().setLayout(layout);  
  93.         layout.setHorizontalGroup(  
  94.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  95.             .addGroup(layout.createSequentialGroup()  
  96.                 .addGap(979797)  
  97.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  98.                     .addComponent(jLabel2)  
  99.                     .addComponent(jLabel3))  
  100.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)  
  101.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)  
  102.                     .addComponent(LoginPwd)  
  103.                     .addComponent(LoginName, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))  
  104.                 .addContainerGap(88, Short.MAX_VALUE))  
  105.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()  
  106.                 .addContainerGap(130, Short.MAX_VALUE)  
  107.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)  
  108.                 .addGap(113113113))  
  109.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()  
  110.                 .addContainerGap(299, Short.MAX_VALUE)  
  111.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)  
  112.                 .addGap(110110110))  
  113.         );  
  114.         layout.setVerticalGroup(  
  115.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  116.             .addGroup(layout.createSequentialGroup()  
  117.                 .addGap(505050)  
  118.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)  
  119.                 .addGap(383838)  
  120.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  121.                     .addComponent(jLabel2)  
  122.                     .addComponent(LoginName, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))  
  123.                 .addGap(262626)  
  124.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  125.                     .addComponent(jLabel3)  
  126.                     .addComponent(LoginPwd, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))  
  127.                 .addGap(181818)  
  128.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)  
  129.                 .addContainerGap(21, Short.MAX_VALUE))  
  130.         );  
  131.   
  132.         pack();  
  133.     }// </editor-fold>                          
  134.   
  135.     private void LoginNameActionPerformed(java.awt.event.ActionEvent evt) {                                            
  136.         // TODO add your handling code here:  
  137. }                                           
  138.   
  139.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  140.           
  141.         //1.先获取用户名和密码  
  142.         String name = LoginName.getText();  
  143.         String password = new String(LoginPwd.getPassword());  
  144.         //2.进行验证  
  145.         if("admin".equals(name)&&"admin".equals(password))  
  146.         {  
  147.             //登陆成功  
  148.             //隐藏LoginForm,显示MainForm  
  149.             this.setVisible(false);  
  150.             new MainForm().setVisible(true);  
  151.         }  
  152.         else  
  153.         {  
  154.             //登录失败  
  155.            JOptionPane.showMessageDialog(this"用户名或密码错误!");  
  156.         }  
  157.   
  158.     }                                          
  159.   
  160.     private void formKeyPressed(java.awt.event.KeyEvent evt) {                                  
  161.        //敲击键盘登陆  
  162.            
  163.     }                                 
  164.   
  165.     private void LoginNameKeyPressed(java.awt.event.KeyEvent evt) {                                       
  166.         //敲击键盘登陆  
  167.         if(evt.getKeyText(evt.getKeyCode()).compareToIgnoreCase("Enter")==0)  
  168.         {  
  169.             jButton1.doClick();   
  170.         }  
  171.     }                                      
  172.   
  173.     private void LoginPwdKeyPressed(java.awt.event.KeyEvent evt) {                                      
  174.         //敲击键盘登陆  
  175.         if(evt.getKeyText(evt.getKeyCode()).compareToIgnoreCase("Enter")==0)  
  176.         {  
  177.             jButton1.doClick();  
  178.         }  
  179.     }                                     
  180.   
  181.     /** 
  182.     * @param args the command line arguments 
  183.     */  
  184.     public static void main(String args[]) {  
  185.         java.awt.EventQueue.invokeLater(new Runnable() {  
  186.             public void run() {  
  187.                 new LoginForm().setVisible(true);  
  188.             }  
  189.         });  
  190.     }  
  191.   
  192.     // Variables declaration - do not modify                       
  193.     private javax.swing.JTextField LoginName;  
  194.     private javax.swing.JPasswordField LoginPwd;  
  195.     private javax.swing.JButton jButton1;  
  196.     private javax.swing.JLabel jLabel1;  
  197.     private javax.swing.JLabel jLabel2;  
  198.     private javax.swing.JLabel jLabel3;  
  199.     // End of variables declaration                     
  200.   
  201. }  


 

 

 

MainForm.java

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. /* 
  7.  * MainForm.java 
  8.  * 
  9.  * Created on 2013-2-26, 18:35:25 
  10.  */  
  11.   
  12. package com.liu.view;  
  13.   
  14. /** 
  15.  * 
  16.  * @author asus 
  17.  */  
  18. public class MainForm extends javax.swing.JFrame {  
  19.   
  20.     /** Creates new form MainForm */  
  21.     public MainForm() {  
  22.         initComponents();  
  23.           
  24.     }  
  25.   
  26.     /** This method is called from within the constructor to 
  27.      * initialize the form. 
  28.      * WARNING: Do NOT modify this code. The content of this method is 
  29.      * always regenerated by the Form Editor. 
  30.      */  
  31.     @SuppressWarnings("unchecked")  
  32.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                            
  33.     private void initComponents() {  
  34.   
  35.         jLabel1 = new javax.swing.JLabel();  
  36.         jPanel1 = new javax.swing.JPanel();  
  37.         jLabel2 = new javax.swing.JLabel();  
  38.         jMenuBar1 = new javax.swing.JMenuBar();  
  39.         配置管理 = new javax.swing.JMenu();  
  40.         jMenuItem1 = new javax.swing.JMenuItem();  
  41.         jMenuItem2 = new javax.swing.JMenuItem();  
  42.         jMenu2 = new javax.swing.JMenu();  
  43.         jMenuItem4 = new javax.swing.JMenuItem();  
  44.         jMenu1 = new javax.swing.JMenu();  
  45.         jMenuItem3 = new javax.swing.JMenuItem();  
  46.   
  47.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
  48.         setTitle("图书管理系统");  
  49.         setBounds(new java.awt.Rectangle(806000));  
  50.         setIconImage(new javax.swing.ImageIcon(getClass().getResource("/com/liu/resouce/logo.jpg")).getImage());  
  51.   
  52.         jLabel1.setFont(new java.awt.Font("宋体"048));  
  53.         jLabel1.setForeground(new java.awt.Color(020451));  
  54.         jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/liu/resouce/main.jpg"))); // NOI18N  
  55.   
  56.         jLabel2.setFont(new java.awt.Font("宋体"048));  
  57.         jLabel2.setForeground(new java.awt.Color(00255));  
  58.         jLabel2.setText("欢迎使用图书借阅管理系统");  
  59.   
  60.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);  
  61.         jPanel1.setLayout(jPanel1Layout);  
  62.         jPanel1Layout.setHorizontalGroup(  
  63.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  64.             .addGroup(jPanel1Layout.createSequentialGroup()  
  65.                 .addGap(383838)  
  66.                 .addComponent(jLabel2)  
  67.                 .addContainerGap(63, Short.MAX_VALUE))  
  68.         );  
  69.         jPanel1Layout.setVerticalGroup(  
  70.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  71.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()  
  72.                 .addContainerGap()  
  73.                 .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))  
  74.         );  
  75.   
  76.         配置管理.setText("配置管理");  
  77.   
  78.         jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));  
  79.         jMenuItem1.setText("类别管理");  
  80.         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {  
  81.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  82.                 jMenuItem1ActionPerformed(evt);  
  83.             }  
  84.         });  
  85.         配置管理.add(jMenuItem1);  
  86.   
  87.         jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));  
  88.         jMenuItem2.setText("图书管理");  
  89.         jMenuItem2.addActionListener(new java.awt.event.ActionListener() {  
  90.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  91.                 jMenuItem2ActionPerformed(evt);  
  92.             }  
  93.         });  
  94.         配置管理.add(jMenuItem2);  
  95.   
  96.         jMenuBar1.add(配置管理);  
  97.   
  98.         jMenu2.setText("借书");  
  99.   
  100.         jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK));  
  101.         jMenuItem4.setText("租书");  
  102.         jMenu2.add(jMenuItem4);  
  103.   
  104.         jMenuBar1.add(jMenu2);  
  105.   
  106.         jMenu1.setText("还书");  
  107.   
  108.         jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));  
  109.         jMenuItem3.setText("还书");  
  110.         jMenu1.add(jMenuItem3);  
  111.   
  112.         jMenuBar1.add(jMenu1);  
  113.   
  114.         setJMenuBar(jMenuBar1);  
  115.   
  116.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
  117.         getContentPane().setLayout(layout);  
  118.         layout.setHorizontalGroup(  
  119.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  120.             .addComponent(jLabel1, 00, Short.MAX_VALUE)  
  121.             .addGroup(layout.createSequentialGroup()  
  122.                 .addGap(222222)  
  123.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
  124.                 .addContainerGap())  
  125.         );  
  126.         layout.setVerticalGroup(  
  127.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  128.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()  
  129.                 .addContainerGap()  
  130.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
  131.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
  132.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE))  
  133.         );  
  134.   
  135.         pack();  
  136.     }// </editor-fold>                          
  137.   
  138.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                             
  139.         // 类型管理  
  140.          new TypeForm().setVisible(true);  
  141.     }                                            
  142.   
  143.     private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                             
  144.         // 图书管理  
  145.         new BookForm().setVisible(true);  
  146.     }                                            
  147.   
  148.     /** 
  149.     * @param args the command line arguments 
  150.     */  
  151.     public static void main(String args[]) {  
  152.         java.awt.EventQueue.invokeLater(new Runnable() {  
  153.             public void run() {  
  154.                 new MainForm().setVisible(true);  
  155.             }  
  156.         });  
  157.     }  
  158.   
  159.     // Variables declaration - do not modify                       
  160.     private javax.swing.JLabel jLabel1;  
  161.     private javax.swing.JLabel jLabel2;  
  162.     private javax.swing.JMenu jMenu1;  
  163.     private javax.swing.JMenu jMenu2;  
  164.     private javax.swing.JMenuBar jMenuBar1;  
  165.     private javax.swing.JMenuItem jMenuItem1;  
  166.     private javax.swing.JMenuItem jMenuItem2;  
  167.     private javax.swing.JMenuItem jMenuItem3;  
  168.     private javax.swing.JMenuItem jMenuItem4;  
  169.     private javax.swing.JPanel jPanel1;  
  170.     private javax.swing.JMenu 配置管理;  
  171.     // End of variables declaration                     
  172.   
  173. }  


 

 

BookForm.java

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. /* 
  7.  * BookForm.java 
  8.  * 
  9.  * Created on 2013-2-28, 8:23:01 
  10.  */  
  11.   
  12. package com.liu.view;  
  13.   
  14. import com.liu.dao.BookDAO;  
  15. import com.liu.dao.TypeDAO;  
  16. import com.liu.po.BookBean;  
  17. import com.liu.po.TypeBean;  
  18. import java.util.Map;  
  19. import java.util.Set;  
  20. import java.util.Vector;  
  21. import javax.swing.DefaultComboBoxModel;  
  22. import javax.swing.JOptionPane;  
  23. import javax.swing.table.DefaultTableModel;  
  24.   
  25. /** 
  26.  * 
  27.  * @author asus 
  28.  */  
  29. public class BookForm extends javax.swing.JFrame {  
  30.   
  31.   
  32.     /** Creates new form BookForm */  
  33.     private Map<Integer,BookBean> map;  
  34.      private Map<Integer,TypeBean> map1;  
  35.     private BookDAO bookDao;  
  36.     private TypeDAO typeDao;  
  37.      
  38.     public BookForm() {  
  39.         initComponents();  
  40.         bookDao = new BookDAO();  
  41.         typeDao = new TypeDAO();  
  42.         map = bookDao.readBook();  
  43.         map1 = typeDao.readType();  
  44.         initType();  
  45.        initData();  
  46.     }  
  47.   
  48.     /** This method is called from within the constructor to 
  49.      * initialize the form. 
  50.      * WARNING: Do NOT modify this code. The content of this method is 
  51.      * always regenerated by the Form Editor. 
  52.      */  
  53.     @SuppressWarnings("unchecked")  
  54.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                            
  55.     private void initComponents() {  
  56.   
  57.         jPanel1 = new javax.swing.JPanel();  
  58.         jScrollPane1 = new javax.swing.JScrollPane();  
  59.         bookTable = new javax.swing.JTable();  
  60.         jPanel2 = new javax.swing.JPanel();  
  61.         bmemo = new javax.swing.JTextField();  
  62.         jButton1 = new javax.swing.JButton();  
  63.         jButton2 = new javax.swing.JButton();  
  64.         jButton3 = new javax.swing.JButton();  
  65.         jButton4 = new javax.swing.JButton();  
  66.         jLabel1 = new javax.swing.JLabel();  
  67.         jLabel2 = new javax.swing.JLabel();  
  68.         jLabel3 = new javax.swing.JLabel();  
  69.         jLabel4 = new javax.swing.JLabel();  
  70.         bid = new javax.swing.JTextField();  
  71.         bname = new javax.swing.JTextField();  
  72.         btype = new javax.swing.JComboBox();  
  73.         jLabel5 = new javax.swing.JLabel();  
  74.         bmoney = new javax.swing.JTextField();  
  75.   
  76.         setTitle("图书管理");  
  77.         setBounds(new java.awt.Rectangle(1005000));  
  78.         setIconImage(new javax.swing.ImageIcon(getClass().getResource("/com/liu/resouce/logo.jpg")).getImage());  
  79.   
  80.         bookTable.setFont(new java.awt.Font("宋体"018)); // NOI18N  
  81.         bookTable.setModel(new javax.swing.table.DefaultTableModel(  
  82.             new Object [][] {  
  83.                 {nullnullnullnullnull},  
  84.                 {nullnullnullnullnull},  
  85.                 {nullnullnullnullnull},  
  86.                 {nullnullnullnullnull},  
  87.                 {nullnullnullnullnull},  
  88.                 {nullnullnullnullnull},  
  89.                 {nullnullnullnullnull},  
  90.                 {nullnullnullnullnull},  
  91.                 {nullnullnullnullnull},  
  92.                 {nullnullnullnullnull}  
  93.             },  
  94.             new String [] {  
  95.                 "序号""图书名称""图书类型""租金""备注"  
  96.             }  
  97.         ) {  
  98.             Class[] types = new Class [] {  
  99.                 java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class  
  100.             };  
  101.             boolean[] canEdit = new boolean [] {  
  102.                 falsefalsefalsefalsefalse  
  103.             };  
  104.   
  105.             public Class getColumnClass(int columnIndex) {  
  106.                 return types [columnIndex];  
  107.             }  
  108.   
  109.             public boolean isCellEditable(int rowIndex, int columnIndex) {  
  110.                 return canEdit [columnIndex];  
  111.             }  
  112.         });  
  113.         bookTable.addMouseListener(new java.awt.event.MouseAdapter() {  
  114.             public void mouseClicked(java.awt.event.MouseEvent evt) {  
  115.                 bookTableMouseClicked(evt);  
  116.             }  
  117.         });  
  118.         jScrollPane1.setViewportView(bookTable);  
  119.   
  120.         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null"详细信息", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("宋体"018))); // NOI18N  
  121.   
  122.         bmemo.setFont(new java.awt.Font("宋体"018));  
  123.   
  124.         jButton1.setText("新增");  
  125.         jButton1.addActionListener(new java.awt.event.ActionListener() {  
  126.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  127.                 jButton1ActionPerformed(evt);  
  128.             }  
  129.         });  
  130.   
  131.         jButton2.setText("保存");  
  132.         jButton2.addActionListener(new java.awt.event.ActionListener() {  
  133.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  134.                 jButton2ActionPerformed(evt);  
  135.             }  
  136.         });  
  137.   
  138.         jButton3.setText("更新");  
  139.         jButton3.addActionListener(new java.awt.event.ActionListener() {  
  140.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  141.                 jButton3ActionPerformed(evt);  
  142.             }  
  143.         });  
  144.   
  145.         jButton4.setText("删除");  
  146.         jButton4.addActionListener(new java.awt.event.ActionListener() {  
  147.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  148.                 jButton4ActionPerformed(evt);  
  149.             }  
  150.         });  
  151.   
  152.         jLabel1.setFont(new java.awt.Font("宋体"018));  
  153.         jLabel1.setText("序号:");  
  154.   
  155.         jLabel2.setFont(new java.awt.Font("宋体"018));  
  156.         jLabel2.setText("名称:");  
  157.   
  158.         jLabel3.setFont(new java.awt.Font("宋体"018));  
  159.         jLabel3.setText("类型:");  
  160.   
  161.         jLabel4.setFont(new java.awt.Font("宋体"018));  
  162.         jLabel4.setText("备注:");  
  163.   
  164.         bid.setFont(new java.awt.Font("宋体"018));  
  165.   
  166.         bname.setFont(new java.awt.Font("宋体"018));  
  167.   
  168.         btype.setFont(new java.awt.Font("宋体"018));  
  169.         btype.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "文学类""教育类""科技类""文艺类" }));  
  170.         btype.addActionListener(new java.awt.event.ActionListener() {  
  171.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  172.                 btypeActionPerformed(evt);  
  173.             }  
  174.         });  
  175.   
  176.         jLabel5.setFont(new java.awt.Font("宋体"018));  
  177.         jLabel5.setText("租金:");  
  178.   
  179.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);  
  180.         jPanel2.setLayout(jPanel2Layout);  
  181.         jPanel2Layout.setHorizontalGroup(  
  182.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  183.             .addGroup(jPanel2Layout.createSequentialGroup()  
  184.                 .addGap(333333)  
  185.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  186.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  187.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  188.                             .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)  
  189.                             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)  
  190.                                 .addComponent(jLabel3)  
  191.                                 .addComponent(jLabel5)  
  192.                                 .addComponent(jLabel4)))  
  193.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))  
  194.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  195.                         .addComponent(jLabel1)  
  196.                         .addGap(333333)))  
  197.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  198.                     .addComponent(bmemo, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)  
  199.                     .addComponent(bid, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)  
  200.                     .addComponent(bname, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)  
  201.                     .addComponent(bmoney, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)  
  202.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  203.                         .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)  
  204.                         .addGap(282828)  
  205.                         .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)  
  206.                         .addGap(303030)  
  207.                         .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)  
  208.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)  
  209.                         .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))  
  210.                     .addComponent(btype, 0375, Short.MAX_VALUE))  
  211.                 .addGap(656565))  
  212.         );  
  213.         jPanel2Layout.setVerticalGroup(  
  214.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  215.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()  
  216.                 .addContainerGap()  
  217.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  218.                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)  
  219.                     .addComponent(bid, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))  
  220.                 .addGap(131313)  
  221.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  222.                     .addComponent(jLabel2)  
  223.                     .addComponent(bname, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))  
  224.                 .addGap(181818)  
  225.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  226.                     .addComponent(jLabel3)  
  227.                     .addComponent(btype, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))  
  228.                 .addGap(262626)  
  229.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  230.                     .addComponent(jLabel5)  
  231.                     .addComponent(bmoney, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))  
  232.                 .addGap(323232)  
  233.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  234.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  235.                         .addComponent(bmemo, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)  
  236.                         .addGap(646464)  
  237.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  238.                             .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)  
  239.                             .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)  
  240.                             .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)  
  241.                             .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))  
  242.                     .addComponent(jLabel4))  
  243.                 .addGap(222222))  
  244.         );  
  245.   
  246.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);  
  247.         jPanel1.setLayout(jPanel1Layout);  
  248.         jPanel1Layout.setHorizontalGroup(  
  249.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  250.             .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 795, Short.MAX_VALUE)  
  251.             .addGroup(jPanel1Layout.createSequentialGroup()  
  252.                 .addGap(505050)  
  253.                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)  
  254.                 .addContainerGap(173, Short.MAX_VALUE))  
  255.         );  
  256.         jPanel1Layout.setVerticalGroup(  
  257.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  258.             .addGroup(jPanel1Layout.createSequentialGroup()  
  259.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)  
  260.                 .addGap(101010)  
  261.                 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))  
  262.         );  
  263.   
  264.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
  265.         getContentPane().setLayout(layout);  
  266.         layout.setHorizontalGroup(  
  267.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  268.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
  269.         );  
  270.         layout.setVerticalGroup(  
  271.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  272.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
  273.         );  
  274.   
  275.         pack();  
  276.     }// </editor-fold>                          
  277.     //表格数据的初始化  
  278.     public void initData(){  
  279.         //加载数据  
  280.         DefaultTableModel dtm = (DefaultTableModel)bookTable.getModel();  
  281.         //清空表  
  282.         while(dtm.getRowCount()>0){  
  283.             dtm.removeRow(0);  
  284.         }  
  285.         //加载数据  
  286.         Set<Integer>set = map.keySet();  
  287.         for(Integer i:set){  
  288.             BookBean bean = map.get(i);  
  289.             Vector v = new Vector();  
  290.             v.add(bean.getId());  
  291.             v.add(bean.getBookName());  
  292.             v.add(bean.getBookType());  
  293.             v.add(bean.getMoney());  
  294.             v.add(bean.getMemo());  
  295.             dtm.addRow(v);  
  296.         }  
  297.     }  
  298.       //获取类别管理的所有类别  
  299.      public void initType(){  
  300.         Set<Integer> set = map1.keySet();  
  301.         DefaultComboBoxModel dcm = (DefaultComboBoxModel)btype.getModel();  
  302.         dcm.removeAllElements();  
  303.         for(Integer i:set){  
  304.             TypeBean bean = map1.get(i);  
  305.             dcm.addElement(bean.getTypeName());  
  306.         }  
  307.   
  308.      }  
  309.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  310.         // 保存功能  
  311.          //先保存文本框里的值  
  312.         String id = bid.getText();  
  313.         String bookName = bname.getText();  
  314.         String bookType = (String) btype.getSelectedItem();  
  315.         String memo = bmemo.getText();  
  316.         String money = bmoney.getText();  
  317.   
  318.         //封装成对象  
  319.         BookBean bean = new BookBean();  
  320.   
  321.         bean.setId(Integer.parseInt(id));  
  322.         bean.setBookName(bookName);  
  323.         bean.setBookType(bookType);  
  324.         bean.setMemo(memo);  
  325.         bean.setMoney(money);  
  326.   
  327.         //将bean放到map里面  
  328.                // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>();  
  329.         map.put(Integer.parseInt(id), bean);  
  330.         //将map放到文件里面  
  331.         bookDao.writeBook(map);  
  332.         //刷新table  
  333.         initData();  
  334.     }                                          
  335.   
  336.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  337.          // 新增时,将文本框里的信息进行清空,并将序列号置为可编辑。  
  338.         bid.setEnabled(true);  
  339.   
  340.         bid.setText("");  
  341.         bname.setText("");  
  342.         btype.setSelectedItem("");  
  343.         bmemo.setText("");  
  344.         bmoney.setText("");  
  345.   
  346.     }                                          
  347.   
  348.     private void bookTableMouseClicked(java.awt.event.MouseEvent evt) {                                         
  349.         //获取选中行号及序列号  
  350.         int currentRow = bookTable.getSelectedRow();  
  351.         //BookBean bean = map.get( currentRow);  
  352.          // 将选中的行,显示到信息栏中  
  353.         bid.setText((Integer) bookTable.getValueAt(currentRow, 0)+"");  
  354.         bname.setText((String) bookTable.getValueAt(currentRow, 1));  
  355.         btype.setSelectedItem((String) bookTable.getValueAt(currentRow, 2));  
  356.         bmoney.setText((String) bookTable.getValueAt(currentRow, 3));  
  357.         bmemo.setText((String) bookTable.getValueAt(currentRow, 4));  
  358.   
  359.         //bmemo.setText(bean.getMemo());  
  360.       
  361.         bid.setEnabled(false);  //序号框不可编辑  
  362.     }                                        
  363.   
  364.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  365.          // 删除操作  
  366.         //获取选中行号及序列号  
  367.         int currentRow = bookTable.getSelectedRow();  
  368.         int id = (Integer)bookTable.getValueAt(currentRow, 0);  
  369.         map.remove(id);  
  370.         bookDao.writeBook(map);  
  371.         JOptionPane.showMessageDialog(this,"类别删除成功");  
  372.         initData();  
  373.     }                                          
  374.   
  375.     private void btypeActionPerformed(java.awt.event.ActionEvent evt) {                                        
  376.         // TODO add your handling code here:  
  377. }                                       
  378.   
  379.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  380.         // 更新操作  
  381.         //先保存文本框里的值  
  382.         int currentRow = bookTable.getSelectedRow();  
  383.         int id = (Integer) bookTable.getValueAt(currentRow, 0);  
  384.   
  385.         String bookName = bname.getText();  
  386.         String bookType = (String) btype.getSelectedItem();  
  387.         String memo = bmemo.getText();  
  388.         String money = bmoney.getText();  
  389.         //封装成对象  
  390.         BookBean bean = new BookBean();  
  391.         bean.setId(id);  
  392.         bean.setBookName(bookName);  
  393.         bean.setBookType(bookType);  
  394.         bean.setMemo(memo);  
  395.         bean.setMoney(money);  
  396.   
  397.         //将bean放到map里面  
  398.                // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>();  
  399.         map.put(id, bean);  
  400.         //将map放到文件里面  
  401.         bookDao.writeBook(map);  
  402.         //刷新table  
  403.         JOptionPane.showMessageDialog(this,"类别更新成功");  
  404.         initData();  
  405.     }                                          
  406.   
  407.     /** 
  408.     * @param args the command line arguments 
  409.     */  
  410.     public static void main(String args[]) {  
  411.         java.awt.EventQueue.invokeLater(new Runnable() {  
  412.             public void run() {  
  413.                 new BookForm().setVisible(true);  
  414.             }  
  415.         });  
  416.     }  
  417.   
  418.     // Variables declaration - do not modify                       
  419.     private javax.swing.JTextField bid;  
  420.     private javax.swing.JTextField bmemo;  
  421.     private javax.swing.JTextField bmoney;  
  422.     private javax.swing.JTextField bname;  
  423.     private javax.swing.JTable bookTable;  
  424.     private javax.swing.JComboBox btype;  
  425.     private javax.swing.JButton jButton1;  
  426.     private javax.swing.JButton jButton2;  
  427.     private javax.swing.JButton jButton3;  
  428.     private javax.swing.JButton jButton4;  
  429.     private javax.swing.JLabel jLabel1;  
  430.     private javax.swing.JLabel jLabel2;  
  431.     private javax.swing.JLabel jLabel3;  
  432.     private javax.swing.JLabel jLabel4;  
  433.     private javax.swing.JLabel jLabel5;  
  434.     private javax.swing.JPanel jPanel1;  
  435.     private javax.swing.JPanel jPanel2;  
  436.     private javax.swing.JScrollPane jScrollPane1;  
  437.     // End of variables declaration                     
  438.   
  439. }  


 

 

 

 

TypeForm.java

 

 

[java]  view plain  copy
 print ?
  1. /* 
  2.  * To change this template, choose Tools | Templates 
  3.  * and open the template in the editor. 
  4.  */  
  5.   
  6. /* 
  7.  * TypeForm.java 
  8.  * 
  9.  * Created on 2013-2-26, 19:07:51 
  10.  */  
  11.   
  12. package com.liu.view;  
  13. import com.liu.dao.TypeDAO;  
  14. import com.liu.po.TypeBean;  
  15. import java.util.HashMap;  
  16. import java.util.Map;  
  17. import java.util.Set;  
  18. import java.util.Vector;  
  19. import javax.swing.JOptionPane;  
  20. import javax.swing.table.DefaultTableModel;  
  21.   
  22. /** 
  23.  * 
  24.  * @author asus 
  25.  */  
  26. public class TypeForm extends javax.swing.JFrame {  
  27.   
  28.     private TypeDAO typeDao;  
  29.     private Map<Integer,TypeBean> map;  
  30.     /** Creates new form TypeForm */  
  31.     public TypeForm() {  
  32.         initComponents();  
  33.         typeDao = new TypeDAO();  
  34.         map = typeDao.readType();  
  35.         initData();  
  36.     }  
  37.   
  38.     /** This method is called from within the constructor to 
  39.      * initialize the form. 
  40.      * WARNING: Do NOT modify this code. The content of this method is 
  41.      * always regenerated by the Form Editor. 
  42.      */  
  43.     @SuppressWarnings("unchecked")  
  44.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                            
  45.     private void initComponents() {  
  46.   
  47.         jPanel1 = new javax.swing.JPanel();  
  48.         jScrollPane1 = new javax.swing.JScrollPane();  
  49.         typeTable = new javax.swing.JTable();  
  50.         jPanel2 = new javax.swing.JPanel();  
  51.         jLabel1 = new javax.swing.JLabel();  
  52.         jLabel2 = new javax.swing.JLabel();  
  53.         jLabel3 = new javax.swing.JLabel();  
  54.         tid = new javax.swing.JTextField();  
  55.         tname = new javax.swing.JTextField();  
  56.         jScrollPane2 = new javax.swing.JScrollPane();  
  57.         tmemo = new javax.swing.JTextArea();  
  58.         jButton1 = new javax.swing.JButton();  
  59.         jButton3 = new javax.swing.JButton();  
  60.         jButton4 = new javax.swing.JButton();  
  61.         jButton5 = new javax.swing.JButton();  
  62.   
  63.         setTitle("类型管理");  
  64.         setBounds(new java.awt.Rectangle(1005000));  
  65.         setIconImage(new javax.swing.ImageIcon(getClass().getResource("/com/liu/resouce/logo.jpg")).getImage());  
  66.   
  67.         typeTable.setFont(new java.awt.Font("宋体"018));  
  68.         typeTable.setModel(new javax.swing.table.DefaultTableModel(  
  69.             new Object [][] {  
  70.                 {nullnullnull},  
  71.                 {nullnullnull},  
  72.                 {nullnullnull},  
  73.                 {nullnullnull}  
  74.             },  
  75.             new String [] {  
  76.                 "序号""类别名称""备注"  
  77.             }  
  78.         ) {  
  79.             Class[] types = new Class [] {  
  80.                 java.lang.Integer.class, java.lang.String.class, java.lang.String.class  
  81.             };  
  82.             boolean[] canEdit = new boolean [] {  
  83.                 falsefalsefalse  
  84.             };  
  85.   
  86.             public Class getColumnClass(int columnIndex) {  
  87.                 return types [columnIndex];  
  88.             }  
  89.   
  90.             public boolean isCellEditable(int rowIndex, int columnIndex) {  
  91.                 return canEdit [columnIndex];  
  92.             }  
  93.         });  
  94.         typeTable.setColumnSelectionAllowed(true);  
  95.         typeTable.addMouseListener(new java.awt.event.MouseAdapter() {  
  96.             public void mouseClicked(java.awt.event.MouseEvent evt) {  
  97.                 typeTableMouseClicked(evt);  
  98.             }  
  99.         });  
  100.         typeTable.addContainerListener(new java.awt.event.ContainerAdapter() {  
  101.             public void componentAdded(java.awt.event.ContainerEvent evt) {  
  102.                 typeTableComponentAdded(evt);  
  103.             }  
  104.         });  
  105.         jScrollPane1.setViewportView(typeTable);  
  106.         typeTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);  
  107.         typeTable.getColumnModel().getColumn(0).setResizable(false);  
  108.         typeTable.getColumnModel().getColumn(2).setResizable(false);  
  109.   
  110.         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null"类别信息", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("宋体"018))); // NOI18N  
  111.   
  112.         jLabel1.setFont(new java.awt.Font("宋体"018));  
  113.         jLabel1.setText("序号:");  
  114.   
  115.         jLabel2.setFont(new java.awt.Font("宋体"018));  
  116.         jLabel2.setText("类别名称:");  
  117.   
  118.         jLabel3.setFont(new java.awt.Font("宋体"018));  
  119.         jLabel3.setText("备注:");  
  120.   
  121.         tid.setFont(new java.awt.Font("宋体"018));  
  122.         tid.addActionListener(new java.awt.event.ActionListener() {  
  123.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  124.                 tidActionPerformed(evt);  
  125.             }  
  126.         });  
  127.   
  128.         tname.setFont(new java.awt.Font("宋体"018));  
  129.   
  130.         tmemo.setColumns(20);  
  131.         tmemo.setFont(new java.awt.Font("Monospaced"018));  
  132.         tmemo.setRows(5);  
  133.         jScrollPane2.setViewportView(tmemo);  
  134.   
  135.         jButton1.setText("保存");  
  136.         jButton1.addActionListener(new java.awt.event.ActionListener() {  
  137.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  138.                 jButton1ActionPerformed(evt);  
  139.             }  
  140.         });  
  141.   
  142.         jButton3.setText("更新");  
  143.         jButton3.addMouseListener(new java.awt.event.MouseAdapter() {  
  144.             public void mouseClicked(java.awt.event.MouseEvent evt) {  
  145.                 jButton3MouseClicked(evt);  
  146.             }  
  147.         });  
  148.         jButton3.addActionListener(new java.awt.event.ActionListener() {  
  149.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  150.                 jButton3ActionPerformed(evt);  
  151.             }  
  152.         });  
  153.   
  154.         jButton4.setText("删除");  
  155.         jButton4.addActionListener(new java.awt.event.ActionListener() {  
  156.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  157.                 jButton4ActionPerformed(evt);  
  158.             }  
  159.         });  
  160.   
  161.         jButton5.setText("新增");  
  162.         jButton5.addActionListener(new java.awt.event.ActionListener() {  
  163.             public void actionPerformed(java.awt.event.ActionEvent evt) {  
  164.                 jButton5ActionPerformed(evt);  
  165.             }  
  166.         });  
  167.   
  168.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);  
  169.         jPanel2.setLayout(jPanel2Layout);  
  170.         jPanel2Layout.setHorizontalGroup(  
  171.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  172.             .addGroup(jPanel2Layout.createSequentialGroup()  
  173.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  174.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  175.                         .addGap(393939)  
  176.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  177.                             .addGroup(jPanel2Layout.createSequentialGroup()  
  178.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
  179.                                 .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)  
  180.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)  
  181.                                 .addComponent(tname, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))  
  182.                             .addGroup(jPanel2Layout.createSequentialGroup()  
  183.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
  184.                                 .addComponent(jLabel3)  
  185.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
  186.                                 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE))  
  187.                             .addGroup(jPanel2Layout.createSequentialGroup()  
  188.                                 .addComponent(jLabel1)  
  189.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
  190.                                 .addComponent(tid, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE))))  
  191.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  192.                         .addGap(707070)  
  193.                         .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)  
  194.                         .addGap(414141)  
  195.                         .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)  
  196.                         .addGap(373737)  
  197.                         .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)  
  198.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)  
  199.                         .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)  
  200.                         .addGap(202020)))  
  201.                 .addGap(838383))  
  202.         );  
  203.         jPanel2Layout.setVerticalGroup(  
  204.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  205.             .addGroup(jPanel2Layout.createSequentialGroup()  
  206.                 .addGap(313131)  
  207.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  208.                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)  
  209.                     .addComponent(tid, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))  
  210.                 .addGap(272727)  
  211.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  212.                     .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)  
  213.                     .addComponent(tname, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))  
  214.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  215.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  216.                         .addGap(454545)  
  217.                         .addComponent(jLabel3))  
  218.                     .addGroup(jPanel2Layout.createSequentialGroup()  
  219.                         .addGap(242424)  
  220.                         .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))  
  221.                 .addGap(353535)  
  222.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
  223.                     .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)  
  224.                     .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)  
  225.                     .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)  
  226.                     .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))  
  227.                 .addGap(181818))  
  228.         );  
  229.   
  230.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);  
  231.         jPanel1.setLayout(jPanel1Layout);  
  232.         jPanel1Layout.setHorizontalGroup(  
  233.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  234.             .addGroup(jPanel1Layout.createSequentialGroup()  
  235.                 .addGap(666666)  
  236.                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)  
  237.                 .addContainerGap(55, Short.MAX_VALUE))  
  238.             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)  
  239.         );  
  240.         jPanel1Layout.setVerticalGroup(  
  241.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  242.             .addGroup(jPanel1Layout.createSequentialGroup()  
  243.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)  
  244.                 .addGap(181818)  
  245.                 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)  
  246.                 .addContainerGap())  
  247.         );  
  248.   
  249.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
  250.         getContentPane().setLayout(layout);  
  251.         layout.setHorizontalGroup(  
  252.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  253.             .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)  
  254.         );  
  255.         layout.setVerticalGroup(  
  256.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
  257.             .addGroup(layout.createSequentialGroup()  
  258.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)  
  259.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))  
  260.         );  
  261.   
  262.         pack();  
  263.     }// </editor-fold>                          
  264.   
  265.     //表格数据的初始化  
  266.     public void initData(){  
  267.         //加载数据  
  268.         DefaultTableModel dtm = (DefaultTableModel)typeTable.getModel();  
  269.         //清空表  
  270.         while(dtm.getRowCount()>0){  
  271.             dtm.removeRow(0);  
  272.         }  
  273.         //加载数据  
  274.         Set<Integer>set = map.keySet();  
  275.         for(Integer i:set){  
  276.             TypeBean bean = map.get(i);  
  277.             Vector v = new Vector();  
  278.             v.add(bean.getId());  
  279.             v.add(bean.getTypeName());  
  280.             v.add(bean.getMemo());  
  281.             dtm.addRow(v);  
  282.         }  
  283.     }  
  284.   
  285.     private void tidActionPerformed(java.awt.event.ActionEvent evt) {                                      
  286.         // TODO add your handling code here:  
  287. }                                     
  288.   
  289.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  290.         //保存类型操作  
  291.        //先保存文本框里的值  
  292.         String id = tid.getText();  
  293.         String typeName = tname.getText();  
  294.         String memo = tmemo.getText();  
  295.         //封装成对象  
  296.         TypeBean bean = new TypeBean();  
  297.         bean.setId(Integer.parseInt(id));  
  298.         bean.setMemo(memo);  
  299.         bean.setTypeName(typeName);  
  300.         //将bean放到map里面  
  301.                // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>();  
  302.         map.put(Integer.parseInt(id), bean);  
  303.         //将map放到文件里面  
  304.         typeDao.writeType(map);  
  305.         //刷新table  
  306.         initData();  
  307.     }                                          
  308.   
  309.     private void typeTableComponentAdded(java.awt.event.ContainerEvent evt) {                                           
  310.         // TODO add your handling code here:  
  311. }                                          
  312.   
  313.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  314.         // 删除操作  
  315.         //获取选中行号及序列号  
  316.         int currentRow = typeTable.getSelectedRow();  
  317.         int id = (Integer)typeTable.getValueAt(currentRow, 0);  
  318.         map.remove(id);  
  319.         typeDao.writeType(map);  
  320.         JOptionPane.showMessageDialog(this,"类别删除成功");  
  321.         initData();  
  322.     }                                          
  323.   
  324.     private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {                                        
  325.   
  326.   
  327.     }                                       
  328.   
  329.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  330.         // 更新操作  
  331.         //先保存文本框里的值  
  332.         int currentRow = typeTable.getSelectedRow();  
  333.         int id = (Integer) typeTable.getValueAt(currentRow, 0);  
  334.           
  335.         String typeName = tname.getText();  
  336.         String memo = tmemo.getText();  
  337.         //封装成对象  
  338.         TypeBean bean = new TypeBean();  
  339.         bean.setId(id);  
  340.         bean.setMemo(memo);  
  341.         bean.setTypeName(typeName);  
  342.         //将bean放到map里面  
  343.                // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>();  
  344.         map.put(id, bean);  
  345.         //将map放到文件里面  
  346.         typeDao.writeType(map);  
  347.         //刷新table  
  348.         JOptionPane.showMessageDialog(this,"类别更新成功");  
  349.         initData();  
  350.     }                                          
  351.   
  352.     private void typeTableMouseClicked(java.awt.event.MouseEvent evt) {                                         
  353.          //获取选中行号及序列号  
  354.         int currentRow = typeTable.getSelectedRow();  
  355.          // 将选中的行,显示到信息栏中  
  356.         tid.setText((Integer) typeTable.getValueAt(currentRow, 0)+"");  
  357.         tname.setText((String) typeTable.getValueAt(currentRow, 1));  
  358.         tmemo.setText((String) typeTable.getValueAt(currentRow, 2));  
  359.   
  360.         tid.setEnabled(false);  //序号框不可编辑  
  361.   
  362.     }                                        
  363.   
  364.     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
  365.         // 新增时,将文本框里的信息进行清空,并将序列号置为可编辑。  
  366.         tid.setEnabled(true);  
  367.         tid.setText("");  
  368.         tname.setText("");  
  369.         tmemo.setText("");  
  370.   
  371.     }                                          
  372.   
  373.     /** 
  374.     * @param args the command line arguments 
  375.     */  
  376.     public static void main(String args[]) {  
  377.         java.awt.EventQueue.invokeLater(new Runnable() {  
  378.             public void run() {  
  379.                 new TypeForm().setVisible(true);  
  380.             }  
  381.         });  
  382.     }  
  383.   
  384.     // Variables declaration - do not modify                       
  385.     private javax.swing.JButton jButton1;  
  386.     private javax.swing.JButton jButton3;  
  387.     private javax.swing.JButton jButton4;  
  388.     private javax.swing.JButton jButton5;  
  389.     private javax.swing.JLabel jLabel1;  
  390.     private javax.swing.JLabel jLabel2;  
  391.     private javax.swing.JLabel jLabel3;  
  392.     private javax.swing.JPanel jPanel1;  
  393.     private javax.swing.JPanel jPanel2;  
  394.     private javax.swing.JScrollPane jScrollPane1;  
  395.     private javax.swing.JScrollPane jScrollPane2;  
  396.     private javax.swing.JTextField tid;  
  397.     private javax.swing.JTextArea tmemo;  
  398.     private javax.swing.JTextField tname;  
  399.     private javax.swing.JTable typeTable;  
  400.     // End of variables declaration                     
  401.   
  402. }  
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值