java学生音信保管类别源代码

作者:杏彩彩票app下载

java学生战表管理种类规划与达成,

本文实例为大家大快朵颐了java学生战表处理种类的切切实实代码,供大家仿照效法,具体内容如下

/* 
 *@copyright by LzyRapx on 2016/4/12. 
 *@name:java学生成绩管理系统. 
 *@功能:学生相关信息,录入,查询,统计,修改等.... 
 *@PS:图形界面的学生管理系统不要求就不做了. 
 */ 

import java.util.Scanner; 
import java.lang.*; 
import java.io.*; 
class Student 
{ 
 private static Student[] s=new Student[100]; //录入学生上限 
 int n=0; 
 private String name; 
 private int num; 
 private String classAge; 
 private int chinese; 
 private int math; 
 private int english; 

 //判断是否有录入学生信息 
 public void judge() throws IOException 
 { 
  int i; 
  char ch; 
  String str; 
  Scanner In=new Scanner(System.in); 
  if(n==0) 
  { 
   System.out.println("你还没有录入任何学生信息,是否录入(Y/N):"); 
   str=In.next(); 
   ch=str.charAt(0); 
   while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
   { 
    System.out.println("输入有误,请重新输入:"); 
    str=In.next(); 
    ch=str.charAt(0); 
   } 
   if(ch=='Y'||ch=='y') 
   { 
    this.add(); 
   } 
   if(ch=='N'||ch=='n') 
   { 
    this.menu(); 
   } 
  } 
 } 

 //菜单 
 public void menu() throws IOException //将异常抛出,调用这个方法去处理异常,如果main方法也将异常抛出,则交给Java虚拟机来处理,下同. 
 { 
  int a; 
  Scanner in=new Scanner(System.in); 
  System.out.println("*************学生信息管理系统*************"); 
  System.out.println("*****  1.录入学生信息   ******"); 
  System.out.println("*****  2.显示学生信息   ******"); 
  System.out.println("*****  3.修改学生信息   ******"); 
  System.out.println("*****  4.删除学生信息   ******"); 
  System.out.println("*****  5.查看学生信息   ******"); 
  System.out.println("*****  0.退出管理系统   ******"); 
  System.out.println("******************************************"); 
  System.out.print("请选择(0~5):"); 
  a=in.nextInt(); 
  while(a<0||a>5) 
  { 
   System.out.print("输入无效,请重新输入:"); 
   a=in.nextInt(); 
  } 
  switch(a) 
  { 
   case 1:this.add();break; 
   case 2:this.show();break; 
   case 3:this.modif();break; 
   case 4:this.delete();break; 
   case 5:this.look();break; 
   case 0:System.out.println("成功退出系统!!!");System.exit(0);break; 
  }    
 } 

 //录入学生信息 
 public void add() throws IOException 
 { 
  String str,str1,str2; 
  int i,num1,t=1; 
  char ch,ch1; 
  FileWriter fw=new FileWriter("E://student.txt",true); //将学生信息录入指定的txt文件中 

  fw.write("    录入的学生信息列表rnrn学号 姓名 班级 语文成绩  数学成绩 英语成绩rn"); 
  Scanner In=new Scanner(System.in); 
  while(t==1) 
  { 
   System.out.println("请输入学生学号:"); 
   num1=In.nextInt(); 

   //判断学号是否重复 
   for(i=0;i<n;i++) 
   { 
    while(s[i].num==num1) 
    { 
     System.out.println("已存在此学号,请重新输入"); 
     System.out.print("请输入学号:"); 
     num1=In.nextInt(); 
    } 
   } 
   s[n].num=num1; 
   str2=String.valueOf(num1); 
   fw.write(str2+" "); 
   System.out.println(); 
   System.out.println("请输入学生姓名:"); 
   s[n].name=In.next(); 
   fw.write(s[n].name+"  "); 
   System.out.println(); 
   System.out.println("请输入学生班级:"); 
   s[n].classAge=In.next(); 
   fw.write(s[n].classAge+" "); 
   System.out.println("请输入学生语文成绩:"); 
   s[n].chinese=In.nextInt(); 
   fw.write(s[n].chinese+" ");      
   System.out.println("请输入学生数学成绩:"); 
   s[n].math=In.nextInt(); 
   fw.write(s[n].chinese+" "); 
   System.out.println("请输入学生英语成绩:"); 
   s[n].english=In.nextInt(); 
   fw.write(s[n].english+"rn"); 
   ++n; 
   fw.close(); 
   System.out.println(); 
   System.out.println("是否继续添加(Y/N)"); 
   str=In.next(); 
   ch=str.charAt(0); 
   while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y') 
   { 
    System.out.println("输入无效,请重新输入:"); 
    str=In.next(); 
    ch=str.charAt(0); 
   } 
   if(ch=='N'||ch=='n') 
   { 
    break; 
   } 
  } 
  System.out.println(); 
  System.out.print("是否返回系统主菜单(Y/N)"); 
  str1=In.next(); 
  ch1=str1.charAt(0); 
  while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n') 
  { 
   System.out.println("输入无效,请重新输入:"); 
   str1=In.next(); 
   ch1=str1.charAt(0); 
  } 
  if(ch1=='Y'||ch1=='y') 
  { 
   this.menu(); 
  } 
  if(ch1=='N'||ch1=='n') 
  { 
   System.out.println(""); 
   System.out.println("你已退出系统!!!"); 
   System.exit(0); 
  } 
 } 

 //显示学生信息 
 public void show() throws IOException 
 { 
  int i; 
  this.judge();  
  System.out.println("本次操作共录入"+n+"位学生!"); 
  System.out.println("你录入的学生信息如下:"); 
  System.out.println(); 
  System.out.println("学号t姓名t班级t语文t数学t英语"); 
  for(i=0;i<n;i++)       
  { 
   System.out.println(s[i].num+"  "+s[i].name+"  "+s[i].classAge+"  "+s[i].chinese+"  "+s[i].math+"  "+s[i].english); 
  } 
  System.out.println("系统返回主菜单!"); 
  this.menu(); 
 } 

 //删除学生信息 
 public void delete() throws IOException 
 { 
  this.judge(); 
  int j=0,t=0,k=0,num1; 
  char ch; 
  String str; 
  Scanner pin=new Scanner(System.in); 
  System.out.println("请输入要删除的学号:"); 
  num1=pin.nextInt(); 
  for(j=0;j<n;j++) 
  { 
   if(s[j].num==num1) 
   { 
    k=1; 
    t=j; 
   } 
  } 
  if(k==0) 
  { 
   System.out.println("对不起!你要删除的学号不存在!"); 
   System.out.println("系统将返回主菜单!"); 
   this.menu(); 
  } 
  if(k==1) 
  { 
   System.out.println("你要删除的学生信息如下:");//打印管理员要删除的学生信息 
   System.out.println("学号t姓名t班级");//本功能暂时不备扩展性 
   System.out.println(s[t].num+"  "+s[t].name+"  "+s[t].classAge); 
   System.out.println(); 
   System.out.println("你确定要删除(Y/N):"); 
   str=pin.next(); 
   ch=str.charAt(0); 
   while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
   { 
    System.out.println("输入无效,请重新输入:"); 
    str=pin.next(); 
    ch=str.charAt(0); 
   } 
   if(ch=='N'||ch=='n') 
   { 
    System.out.println(); 
    System.out.println("系统返回主菜单!"); 
    this.menu(); 
   } 
   if(ch=='Y'||ch=='y') 
   { 
    for(j=t;j<n-1;j++) 
    { 
     s[j]=s[j+1]; 
    } 
    n--; 
    System.out.println("学生数据成功删除!"); 
    System.out.println("系统返回主菜单!"); 
    this.menu(); 
   } 
  } 
 } 
 //查看学生信息 
 public void look() throws IOException 
 { 
  FileReader fr=new FileReader("E://student.txt"); //查看txt中的学生信息 
  int a; 
  while((a=fr.read())!=-1) 
  { 
   System.out.print((char)a); 
  } 
  fr.close(); 
  System.out.println("系统返回主菜单!"); 
  System.out.println(); 
  this.menu(); 
 } 

 //修改学生信息 
 public void modif() throws IOException 
 { 
  this.judge(); 
  int j=0,t=0,k=0,num2,num3,moi,c=1; 
  char ch; 
  String str,str1,str2; 
  Scanner pin=new Scanner(System.in); 
  System.out.println("请输入要修改的学号:"); 
  num2=pin.nextInt(); 
  for(j=0;j<n;j++) 
  { 
   if(s[j].num==num2) 
   { 
    k=1; 
    t=j; 
   } 
  } 
  if(k==0) 
  { 
   System.out.println("对不起!你要修改的学号不存在!"); 
   System.out.println("系统将返回主菜单!"); 
   this.menu(); 
  } 
  if(k==1) 
  { 
   //打印将要要删除的学生信息 
   System.out.println("你要修改的学生信息如下:"); 
   System.out.println("学号t姓名t班级"); 
   System.out.println(s[t].num+"  "+s[t].name+"  "+s[t].classAge); 
   System.out.println("语文t数学t英语"); 
   System.out.println(s[t].chinese+"  "+s[t].math+"  "+s[t].english); 
   System.out.println(); 
   System.out.println("你确定要修改(Y/N):"); 
   str=pin.next(); 
   ch=str.charAt(0); 
   while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
   { 
    System.out.println("输入无效,请重新输入:"); 
    str=pin.next(); 
    ch=str.charAt(0); 
   } 
   if(ch=='N'||ch=='n') 
   { 
    System.out.println(); 
    System.out.println("系统返回主菜单!"); 
    this.menu(); 
   } 
   while(c==1) 
   { 
    if(ch=='Y'||ch=='y') 
    { 
     System.out.println("****************************************"); 
     System.out.println("*****   1.修改学号   *****"); 
     System.out.println("*****   2.修改班级   *****"); 
     System.out.println("*****   3.修改姓名   *****"); 
     System.out.println("****************************************"); 
     System.out.println("请选择:"); 
     moi=pin.nextInt(); 
     switch(moi) 
     { 
      case 1:System.out.print("请输入新的学号:");num3=pin.nextInt();s[t].num=num3;break; 
      case 2:System.out.print("请输入新的班级:");str1=pin.next();s[t].classAge=str1;break; 
      case 3:System.out.print("请输入新的姓名:");str2=pin.next();s[t].name=str2;break; 
     } 
     System.out.println("数据已成功修改!"); 
    } 
    System.out.print("是否继续修改(Y/N)"); 
    str=pin.next(); 
    ch=str.charAt(0); 
    System.out.println(); 
    while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
    { 
     System.out.print("输入无效,请重新输入:"); 
     str=pin.next(); 
     ch=str.charAt(0); 
    } 
    if(ch=='N'||ch=='n') 
    { 
     break; 
    } 
   }  
  } 
  System.out.println(); 
  System.out.println("系统返回主菜单!"); 
  this.menu(); 
 } 

 public static void main(String[] args) throws IOException 
 {  
  Student stu=new Student(); 
  for(int i=0;i<100;i++) 
  { 
   s[i]=new Student(); 
  } 
  stu.menu(); 
 } 
} 

一对效果图:

图片 1

图片 2

图片 3

图片 4

图片 5

以上正是本文的全体内容,希望对我们的读书抱有助于,也冀望大家多都赐教帮客之家。

本文实例为大家大快朵颐了java学生战表管理体系的切实代码,供大家参照他事他说加以考察,具体内容如下 /* *@copyright by Lz...

正文实例为大家大快朵颐了java学生音讯保管种类的求实代码,落成学生音信: 扩张int[] a=new int[9] 、删除 、查找、改动,供大家参谋,具体内容如下

书籍管理种类java代码达成,图书管理种类java

正文实例为大家享受了java完结图书管理类别的切切实实代码,供大家参照他事他说加以考察,具体内容如下

/* (程序底部注释初阶)
* 程序的版权和版本注解部分
* Copyright (c) 2013, 南平大学电脑高校学生
* All rights reserved.
* 文件名称:    《图书管理体系——java》                         
* 作    者:       刘江波                      
* 完毕日期:    二〇一三     年  3     月     1   日
* 版 本 号:    v3.0    

* 对任务及求解方法的描述部分
* 难题呈报: 
* 程序尾部的笺注截至
*/

文件包的创造景况:

图片 6

BookDao.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

package com.liu.dao; 

import com.liu.po.BookBean; 
import java.io.*; 
import java.util.HashMap; 
import java.util.Map; 
import java.util.logging.Level; 
import java.util.logging.Logger; 

/** 
 * 
 * @author asus 
 */ 
public class BookDAO { 
 // 写 
 public void writeBook(Map<Integer,BookBean >bookMap){ 
 // 
 FileOutputStream fos = null; 
 ObjectOutputStream oos = null; 
 try { 
  fos = new FileOutputStream("F:\缓存区\book.txt"); 
  oos = new ObjectOutputStream(fos); 
  oos.writeObject(bookMap); 
  //清空缓存区 
  oos.flush(); 
 } 
 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); 
 } 
 finally{ 
  try{ 
  //先开后闭 
   oos.close(); 
   fos.close(); 
  }catch(IOException ex){ 
  Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE,null,ex); 
  } 
 } 
 } 

 //读 
 public Map<Integer,BookBean>readBook(){ 
 FileInputStream fis = null; 
 ObjectInputStream ois = null; 
 Map<Integer, BookBean> map = null; 
 try { 
  fis = new FileInputStream("F:\缓存区\book.txt"); 
  ois = new ObjectInputStream(fis); 
  map = (Map<Integer, BookBean>) 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,BookBean>();//出现异常时,进行创建map 
 } finally{ 
  try { 
  if(ois!=null){ 
   ois.close(); 
  } 
  if(fis!=null){ 
   fis.close(); 
  } 

  } catch (IOException ex) { 
  Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex); 
  } 
 } 
 return map; 
 } 
} 

 TypeDao.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

package com.liu.dao; 

import com.liu.po.TypeBean; 
import java.io.*; 
import java.util.*; 
import java.util.logging.*; 
/** 
 * 
 * 对文件进行读和写操作 
 */ 
public class TypeDAO { 

 // 写 
 public void writeType(Map<Integer,TypeBean >typeMap){ 
 // 
 FileOutputStream fos = null; 
 ObjectOutputStream oos = null; 
 try { 
  fos = new FileOutputStream("F:\缓存区\type.txt"); 
  oos = new ObjectOutputStream(fos); 
  oos.writeObject(typeMap); 
  //清空缓存区 
  oos.flush(); 
 } 
 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); 
 } 
 finally{ 
  try{ 
  //先开后闭 
   oos.close(); 
   fos.close(); 
  }catch(IOException ex){ 
  Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE,null,ex); 
  } 
 } 
 } 

 //读 
 public Map<Integer,TypeBean>readType(){ 
 FileInputStream fis = null; 
 ObjectInputStream ois = null; 
 Map<Integer, TypeBean> map = null; 
 try { 
  fis = new FileInputStream("F:\缓存区\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>();//出现异常时,进行创建map 
 } finally{ 
  try { 
  if(ois!=null){ 
   ois.close(); 
  } 
  if(fis!=null){ 
   fis.close(); 
  } 

  } catch (IOException ex) { 
  Logger.getLogger(TypeDAO.class.getName()).log(Level.SEVERE, null, ex); 
  } 
 } 
 return map; 
 } 
} 

BookBean.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

package com.liu.po; 

import java.io.Serializable; 

/** 
 * 
 * @author asus 
 */ 
public class BookBean implements Serializable{ 

 private int id; 
 private String bookName; 
 private String bookType; 
 private String memo; 
 private String money; 

 /** 
 * @return the id 
 */ 
 public int getId() { 
 return id; 
 } 

 /** 
 * @param id the id to set 
 */ 
 public void setId(int id) { 
 this.id = id; 
 } 

 /** 
 * @return the bookName 
 */ 
 public String getBookName() { 
 return bookName; 
 } 

 /** 
 * @param bookName the bookName to set 
 */ 
 public void setBookName(String bookName) { 
 this.bookName = bookName; 
 } 

 /** 
 * @return the bookType 
 */ 
 public String getBookType() { 
 return bookType; 
 } 

 /** 
 * @param bookType the bookType to set 
 */ 
 public void setBookType(String bookType) { 
 this.bookType = bookType; 
 } 

 /** 
 * @return the memo 
 */ 
 public String getMemo() { 
 return memo; 
 } 

 /** 
 * @param memo the memo to set 
 */ 
 public void setMemo(String memo) { 
 this.memo = memo; 
 } 

 /** 
 * @return the money 
 */ 
 public String getMoney() { 
 return money; 
 } 

 /** 
 * @param money the money to set 
 */ 
 public void setMoney(String money) { 
 this.money = money; 
 } 
} 

TypeBean.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

package com.liu.po; 

/** 
 * 
 * @author asus 
 */ 
import java.io.Serializable; 

public class TypeBean implements Serializable{ 

 private int id; 
 private String typeName; 
 private String memo; 

 /** 
 * @return the id 
 */ 
 public int getId() { 
 return id; 
 } 

 /** 
 * @param id the id to set 
 */ 
 public void setId(int id) { 
 this.id = id; 
 } 

 /** 
 * @return the typeName 
 */ 
 public String getTypeName() { 
 return typeName; 
 } 

 /** 
 * @param typeName the typeName to set 
 */ 
 public void setTypeName(String typeName) { 
 this.typeName = typeName; 
 } 

 /** 
 * @return the memo 
 */ 
 public String getMemo() { 
 return memo; 
 } 

 /** 
 * @param memo the memo to set 
 */ 
 public void setMemo(String memo) { 
 this.memo = memo; 
 } 


} 

LoginForm.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

/* 
 * LoginForm.java 
 * 
 * Created on 2013-2-26, 18:33:36 
 */ 

package com.liu.view; 

import java.awt.event.KeyAdapter; 
import java.awt.event.KeyEvent; 
import javax.swing.JOptionPane; 

/** 
 * 
 * @author asus 
 */ 
public class LoginForm extends javax.swing.JFrame { 

 /** Creates new form LoginForm */ 
 public LoginForm() { 
 initComponents(); 
 } 

 /** 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() { 

 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) { 
  formKeyPressed(evt); 
  } 
 }); 

 jLabel1.setFont(new java.awt.Font("宋体", 0, 36)); 
 jLabel1.setForeground(new java.awt.Color(204, 0, 0)); 
 jLabel1.setText("图书管理系统"); 

 jLabel2.setFont(new java.awt.Font("宋体", 0, 24)); 
 jLabel2.setText("用户名:"); 

 jLabel3.setFont(new java.awt.Font("宋体", 0, 24)); 
 jLabel3.setText("密码:"); 

 LoginName.setName(""); // NOI18N 
 LoginName.addActionListener(new java.awt.event.ActionListener() { 
  public void actionPerformed(java.awt.event.ActionEvent evt) { 
  LoginNameActionPerformed(evt); 
  } 
 }); 
 LoginName.addKeyListener(new java.awt.event.KeyAdapter() { 
  public void keyPressed(java.awt.event.KeyEvent evt) { 
  LoginNameKeyPressed(evt); 
  } 
 }); 

 LoginPwd.addKeyListener(new java.awt.event.KeyAdapter() { 
  public void keyPressed(java.awt.event.KeyEvent evt) { 
  LoginPwdKeyPressed(evt); 
  } 
 }); 

 jButton1.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N 
 jButton1.setText("登录"); 
 jButton1.addActionListener(new java.awt.event.ActionListener() { 
  public void actionPerformed(java.awt.event.ActionEvent evt) { 
  jButton1ActionPerformed(evt); 
  } 
 }); 

 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
 getContentPane().setLayout(layout); 
 layout.setHorizontalGroup( 
  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addGroup(layout.createSequentialGroup() 
  .addGap(97, 97, 97) 
  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
   .addComponent(jLabel2) 
   .addComponent(jLabel3)) 
  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 
   .addComponent(LoginPwd) 
   .addComponent(LoginName, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)) 
  .addContainerGap(88, Short.MAX_VALUE)) 
  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
  .addContainerGap(130, Short.MAX_VALUE) 
  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE) 
  .addGap(113, 113, 113)) 
  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
  .addContainerGap(299, Short.MAX_VALUE) 
  .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE) 
  .addGap(110, 110, 110)) 
 ); 
 layout.setVerticalGroup( 
  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addGroup(layout.createSequentialGroup() 
  .addGap(50, 50, 50) 
  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) 
  .addGap(38, 38, 38) 
  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
   .addComponent(jLabel2) 
   .addComponent(LoginName, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)) 
  .addGap(26, 26, 26) 
  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
   .addComponent(jLabel3) 
   .addComponent(LoginPwd, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)) 
  .addGap(18, 18, 18) 
  .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) 
  .addContainerGap(21, Short.MAX_VALUE)) 
 ); 

 pack(); 
 }// </editor-fold>    

 private void LoginNameActionPerformed(java.awt.event.ActionEvent evt) {      
 // TODO add your handling code here: 
}      

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {      

 //1.先获取用户名和密码 
 String name = LoginName.getText(); 
 String password = new String(LoginPwd.getPassword()); 
 //2.进行验证 
 if("admin".equals(name)&&"admin".equals(password)) 
 { 
  //登陆成功 
  //隐藏LoginForm,显示MainForm 
  this.setVisible(false); 
  new MainForm().setVisible(true); 
 } 
 else 
 { 
  //登录失败 
  JOptionPane.showMessageDialog(this, "用户名或密码错误!"); 
 } 

 }      

 private void formKeyPressed(java.awt.event.KeyEvent evt) {     
 //敲击键盘登陆 

 }     

 private void LoginNameKeyPressed(java.awt.event.KeyEvent evt) {     
 //敲击键盘登陆 
 if(evt.getKeyText(evt.getKeyCode()).compareToIgnoreCase("Enter")==0) 
 { 
  jButton1.doClick(); 
 } 
 }     

 private void LoginPwdKeyPressed(java.awt.event.KeyEvent evt) {     
 //敲击键盘登陆 
 if(evt.getKeyText(evt.getKeyCode()).compareToIgnoreCase("Enter")==0) 
 { 
  jButton1.doClick(); 
 } 
 }     

 /** 
 * @param args the command line arguments 
 */ 
 public static void main(String args[]) { 
 java.awt.EventQueue.invokeLater(new Runnable() { 
  public void run() { 
  new LoginForm().setVisible(true); 
  } 
 }); 
 } 

 // Variables declaration - do not modify   
 private javax.swing.JTextField LoginName; 
 private javax.swing.JPasswordField LoginPwd; 
 private javax.swing.JButton jButton1; 
 private javax.swing.JLabel jLabel1; 
 private javax.swing.JLabel jLabel2; 
 private javax.swing.JLabel jLabel3; 
 // End of variables declaration   

} 

图片 7

MainForm.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

/* 
 * MainForm.java 
 * 
 * Created on 2013-2-26, 18:35:25 
 */ 

package com.liu.view; 

/** 
 * 
 * @author asus 
 */ 
public class MainForm extends javax.swing.JFrame { 

 /** Creates new form MainForm */ 
 public MainForm() { 
 initComponents(); 

 } 

 /** 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() { 

 jLabel1 = new javax.swing.JLabel(); 
 jPanel1 = new javax.swing.JPanel(); 
 jLabel2 = new javax.swing.JLabel(); 
 jMenuBar1 = new javax.swing.JMenuBar(); 
 配置管理 = new javax.swing.JMenu(); 
 jMenuItem1 = new javax.swing.JMenuItem(); 
 jMenuItem2 = new javax.swing.JMenuItem(); 
 jMenu2 = new javax.swing.JMenu(); 
 jMenuItem4 = new javax.swing.JMenuItem(); 
 jMenu1 = new javax.swing.JMenu(); 
 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) 
  .addGroup(jPanel1Layout.createSequentialGroup() 
  .addGap(38, 38, 38) 
  .addComponent(jLabel2) 
  .addContainerGap(63, Short.MAX_VALUE)) 
 ); 
 jPanel1Layout.setVerticalGroup( 
  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 
  .addContainerGap() 
  .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)) 
 ); 

 配置管理.setText("配置管理"); 

 jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(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); 
  } 
 }); 
 配置管理.add(jMenuItem1); 

 jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(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); 
  } 
 }); 
 配置管理.add(jMenuItem2); 

 jMenuBar1.add(配置管理); 

 jMenu2.setText("借书"); 

 jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(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.KeyStroke.getKeyStroke(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 layout = new javax.swing.GroupLayout(getContentPane()); 
 getContentPane().setLayout(layout); 
 layout.setHorizontalGroup( 
  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addComponent(jLabel1, 0, 0, Short.MAX_VALUE) 
  .addGroup(layout.createSequentialGroup() 
  .addGap(22, 22, 22) 
  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
  .addContainerGap()) 
 ); 
 layout.setVerticalGroup( 
  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
  .addContainerGap() 
  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)) 
 ); 

 pack(); 
 }// </editor-fold>    

 private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 类型管理 
  new TypeForm().setVisible(true); 
 }      

 private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 图书管理 
 new BookForm().setVisible(true); 
 }      

 /** 
 * @param args the command line arguments 
 */ 
 public static void main(String args[]) { 
 java.awt.EventQueue.invokeLater(new Runnable() { 
  public void run() { 
  new MainForm().setVisible(true); 
  } 
 }); 
 } 

 // Variables declaration - do not modify   
 private javax.swing.JLabel jLabel1; 
 private javax.swing.JLabel jLabel2; 
 private javax.swing.JMenu jMenu1; 
 private javax.swing.JMenu jMenu2; 
 private javax.swing.JMenuBar jMenuBar1; 
 private javax.swing.JMenuItem jMenuItem1; 
 private javax.swing.JMenuItem jMenuItem2; 
 private javax.swing.JMenuItem jMenuItem3; 
 private javax.swing.JMenuItem jMenuItem4; 
 private javax.swing.JPanel jPanel1; 
 private javax.swing.JMenu 配置管理; 
 // End of variables declaration   

} 

图片 8

BookForm.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

/* 
 * BookForm.java 
 * 
 * Created on 2013-2-28, 8:23:01 
 */ 

package com.liu.view; 

import com.liu.dao.BookDAO; 
import com.liu.dao.TypeDAO; 
import com.liu.po.BookBean; 
import com.liu.po.TypeBean; 
import java.util.Map; 
import java.util.Set; 
import java.util.Vector; 
import javax.swing.DefaultComboBoxModel; 
import javax.swing.JOptionPane; 
import javax.swing.table.DefaultTableModel; 

/** 
 * 
 * @author asus 
 */ 
public class BookForm extends javax.swing.JFrame { 


 /** Creates new form BookForm */ 
 private Map<Integer,BookBean> map; 
 private Map<Integer,TypeBean> map1; 
 private BookDAO bookDao; 
 private TypeDAO typeDao; 

 public BookForm() { 
 initComponents(); 
 bookDao = new BookDAO(); 
 typeDao = new TypeDAO(); 
 map = bookDao.readBook(); 
 map1 = typeDao.readType(); 
 initType(); 
 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(); 
 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)); // NOI18N 
 bookTable.setModel(new javax.swing.table.DefaultTableModel( 
  new Object [][] { 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null}, 
  {null, null, null, null, null} 
  }, 
  new String [] { 
  "序号", "图书名称", "图书类型", "租金", "备注" 
  } 
 ) { 
  Class[] types = new Class [] { 
  java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class 
  }; 
  boolean[] canEdit = new boolean [] { 
  false, false, false, false, false 
  }; 

  public Class getColumnClass(int columnIndex) { 
  return types [columnIndex]; 
  } 

  public boolean isCellEditable(int rowIndex, int columnIndex) { 
  return canEdit [columnIndex]; 
  } 
 }); 
 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_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("宋体", 0, 18))); // NOI18N 

 bmemo.setFont(new java.awt.Font("宋体", 0, 18)); 

 jButton1.setText("新增"); 
 jButton1.addActionListener(new java.awt.event.ActionListener() { 
  public void actionPerformed(java.awt.event.ActionEvent evt) { 
  jButton1ActionPerformed(evt); 
  } 
 }); 

 jButton2.setText("保存"); 
 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("删除"); 
 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("序号:"); 

 jLabel2.setFont(new java.awt.Font("宋体", 0, 18)); 
 jLabel2.setText("名称:"); 

 jLabel3.setFont(new java.awt.Font("宋体", 0, 18)); 
 jLabel3.setText("类型:"); 

 jLabel4.setFont(new java.awt.Font("宋体", 0, 18)); 
 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(new String[] { "文学类", "教育类", "科技类", "文艺类" })); 
 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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addGroup(jPanel2Layout.createSequentialGroup() 
  .addGap(33, 33, 33) 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
   .addGroup(jPanel2Layout.createSequentialGroup() 
   .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE) 
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 
    .addComponent(jLabel3) 
    .addComponent(jLabel5) 
    .addComponent(jLabel4))) 
   .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)) 
   .addGroup(jPanel2Layout.createSequentialGroup() 
   .addComponent(jLabel1) 
   .addGap(33, 33, 33))) 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
   .addComponent(bmemo, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) 
   .addComponent(bid, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) 
   .addComponent(bname, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) 
   .addComponent(bmoney, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) 
   .addGroup(jPanel2Layout.createSequentialGroup() 
   .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) 
   .addGap(28, 28, 28) 
   .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) 
   .addGap(30, 30, 30) 
   .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) 
   .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) 
   .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)) 
   .addComponent(btype, 0, 375, Short.MAX_VALUE)) 
  .addGap(65, 65, 65)) 
 ); 
 jPanel2Layout.setVerticalGroup( 
  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() 
  .addContainerGap() 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
   .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 
   .addComponent(bid, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) 
  .addGap(13, 13, 13) 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
   .addComponent(jLabel2) 
   .addComponent(bname, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) 
  .addGap(18, 18, 18) 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
   .addComponent(jLabel3) 
   .addComponent(btype, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) 
  .addGap(26, 26, 26) 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
   .addComponent(jLabel5) 
   .addComponent(bmoney, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)) 
  .addGap(32, 32, 32) 
  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
   .addGroup(jPanel2Layout.createSequentialGroup() 
   .addComponent(bmemo, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE) 
   .addGap(64, 64, 64) 
   .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) 
    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) 
    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) 
    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))) 
   .addComponent(jLabel4)) 
  .addGap(22, 22, 22)) 
 ); 

 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
 jPanel1.setLayout(jPanel1Layout); 
 jPanel1Layout.setHorizontalGroup( 
  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 795, Short.MAX_VALUE) 
  .addGroup(jPanel1Layout.createSequentialGroup() 
  .addGap(50, 50, 50) 
  .addComponent(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.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE) 
  .addGap(10, 10, 10) 
  .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
 ); 

 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
 getContentPane().setLayout(layout); 
 layout.setHorizontalGroup( 
  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
 ); 
 layout.setVerticalGroup( 
  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
 ); 

 pack(); 
 }// </editor-fold>    
 //表格数据的初始化 
 public void initData(){ 
 //加载数据 
 DefaultTableModel dtm = (DefaultTableModel)bookTable.getModel(); 
 //清空表 
 while(dtm.getRowCount()>0){ 
  dtm.removeRow(0); 
 } 
 //加载数据 
 Set<Integer>set = map.keySet(); 
 for(Integer i:set){ 
  BookBean bean = map.get(i); 
  Vector v = new Vector(); 
  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.removeAllElements(); 
 for(Integer i:set){ 
  TypeBean bean = map1.get(i); 
  dcm.addElement(bean.getTypeName()); 
 } 

 } 
 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 保存功能 
  //先保存文本框里的值 
 String id = bid.getText(); 
 String bookName = bname.getText(); 
 String bookType = (String) btype.getSelectedItem(); 
 String memo = bmemo.getText(); 
 String money = bmoney.getText(); 

 //封装成对象 
 BookBean bean = new BookBean(); 

 bean.setId(Integer.parseInt(id)); 
 bean.setBookName(bookName); 
 bean.setBookType(bookType); 
 bean.setMemo(memo); 
 bean.setMoney(money); 

 //将bean放到map里面 
  // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); 
 map.put(Integer.parseInt(id), bean); 
 //将map放到文件里面 
 bookDao.writeBook(map); 
 //刷新table 
 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); //序号框不可编辑 
 }     

 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {      
  // 删除操作 
 //获取选中行号及序列号 
 int currentRow = bookTable.getSelectedRow(); 
 int id = (Integer)bookTable.getValueAt(currentRow, 0); 
 map.remove(id); 
 bookDao.writeBook(map); 
 JOptionPane.showMessageDialog(this,"类别删除成功"); 
 initData(); 
 }      

 private void btypeActionPerformed(java.awt.event.ActionEvent evt) {     
 // TODO add your handling code here: 
}     

 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 更新操作 
 //先保存文本框里的值 
 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(); 
 //封装成对象 
 BookBean bean = new BookBean(); 
 bean.setId(id); 
 bean.setBookName(bookName); 
 bean.setBookType(bookType); 
 bean.setMemo(memo); 
 bean.setMoney(money); 

 //将bean放到map里面 
  // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); 
 map.put(id, bean); 
 //将map放到文件里面 
 bookDao.writeBook(map); 
 //刷新table 
 JOptionPane.showMessageDialog(this,"类别更新成功"); 
 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   

} 

图片 9

TypeForm.java

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 

/* 
 * TypeForm.java 
 * 
 * Created on 2013-2-26, 19:07:51 
 */ 

package com.liu.view; 
import com.liu.dao.TypeDAO; 
import com.liu.po.TypeBean; 
import java.util.HashMap; 
import java.util.Map; 
import java.util.Set; 
import java.util.Vector; 
import javax.swing.JOptionPane; 
import javax.swing.table.DefaultTableModel; 

/** 
 * 
 * @author asus 
 */ 
public class TypeForm extends javax.swing.JFrame { 

 private TypeDAO typeDao; 
 private Map<Integer,TypeBean> map; 
 /** Creates new form TypeForm */ 
 public TypeForm() { 
 initComponents(); 
 typeDao = new TypeDAO(); 
 map = typeDao.readType(); 
 initData(); 
 } 

 /** This method is called from within the constructor to 
 * initialize the form. 
 * WARNING: Do NOT modify this code. The content of this method is 
 * always regenerated by the Form Editor. 
 */ 
 @SuppressWarnings("unchecked") 
 // <editor-fold defaultstate="collapsed" desc="Generated Code">    
 private void initComponents() { 

 jPanel1 = new javax.swing.JPanel(); 
 jScrollPane1 = new javax.swing.JScrollPane(); 
 typeTable = new javax.swing.JTable(); 
 jPanel2 = new javax.swing.JPanel(); 
 jLabel1 = new javax.swing.JLabel(); 
 jLabel2 = new javax.swing.JLabel(); 
 jLabel3 = new javax.swing.JLabel(); 
 tid = new javax.swing.JTextField(); 
 tname = new javax.swing.JTextField(); 
 jScrollPane2 = new javax.swing.JScrollPane(); 
 tmemo = new javax.swing.JTextArea(); 
 jButton1 = new javax.swing.JButton(); 
 jButton3 = new javax.swing.JButton(); 
 jButton4 = new javax.swing.JButton(); 
 jButton5 = new javax.swing.JButton(); 

 setTitle("类型管理"); 
 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 [] { 
  "序号", "类别名称", "备注" 
  } 
 ) { 
  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, "类别信息", 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("类别名称:"); 

 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("保存"); 
 jButton1.addActionListener(new java.awt.event.ActionListener() { 
  public void actionPerformed(java.awt.event.ActionEvent evt) { 
  jButton1ActionPerformed(evt); 
  } 
 }); 

 jButton3.setText("更新"); 
 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("删除"); 
 jButton4.addActionListener(new java.awt.event.ActionListener() { 
  public void actionPerformed(java.awt.event.ActionEvent evt) { 
  jButton4ActionPerformed(evt); 
  } 
 }); 

 jButton5.setText("新增"); 
 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)) 
 ); 

 pack(); 
 }// </editor-fold>    

 //表格数据的初始化 
 public void initData(){ 
 //加载数据 
 DefaultTableModel dtm = (DefaultTableModel)typeTable.getModel(); 
 //清空表 
 while(dtm.getRowCount()>0){ 
  dtm.removeRow(0); 
 } 
 //加载数据 
 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) {      
 //保存类型操作 
 //先保存文本框里的值 
 String id = tid.getText(); 
 String typeName = tname.getText(); 
 String memo = tmemo.getText(); 
 //封装成对象 
 TypeBean bean = new TypeBean(); 
 bean.setId(Integer.parseInt(id)); 
 bean.setMemo(memo); 
 bean.setTypeName(typeName); 
 //将bean放到map里面 
  // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); 
 map.put(Integer.parseInt(id), bean); 
 //将map放到文件里面 
 typeDao.writeType(map); 
 //刷新table 
 initData(); 
 }      

 private void typeTableComponentAdded(java.awt.event.ContainerEvent evt) {      
 // TODO add your handling code here: 
}      

 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 删除操作 
 //获取选中行号及序列号 
 int currentRow = typeTable.getSelectedRow(); 
 int id = (Integer)typeTable.getValueAt(currentRow, 0); 
 map.remove(id); 
 typeDao.writeType(map); 
 JOptionPane.showMessageDialog(this,"类别删除成功"); 
 initData(); 
 }      

 private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {     


 }     

 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 更新操作 
 //先保存文本框里的值 
 int currentRow = typeTable.getSelectedRow(); 
 int id = (Integer) typeTable.getValueAt(currentRow, 0); 

 String typeName = tname.getText(); 
 String memo = tmemo.getText(); 
 //封装成对象 
 TypeBean bean = new TypeBean(); 
 bean.setId(id); 
 bean.setMemo(memo); 
 bean.setTypeName(typeName); 
 //将bean放到map里面 
  // Map<Integer,TypeBean>map = new HashMap<Integer,TypeBean>(); 
 map.put(id, bean); 
 //将map放到文件里面 
 typeDao.writeType(map); 
 //刷新table 
 JOptionPane.showMessageDialog(this,"类别更新成功"); 
 initData(); 
 }      

 private void typeTableMouseClicked(java.awt.event.MouseEvent evt) {      
  //获取选中行号及序列号 
 int currentRow = typeTable.getSelectedRow(); 
  // 将选中的行,显示到信息栏中 
 tid.setText((Integer) typeTable.getValueAt(currentRow, 0)+""); 
 tname.setText((String) typeTable.getValueAt(currentRow, 1)); 
 tmemo.setText((String) typeTable.getValueAt(currentRow, 2)); 

 tid.setEnabled(false); //序号框不可编辑 

 }     

 private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {      
 // 新增时,将文本框里的信息进行清空,并将序列号置为可编辑。 
 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   

} 

图片 10

如上正是本文的全部内容,希望对咱们的读书抱有利于,也可望我们多都赐教帮客之家。

本文实例为大家享用了java实现图书管理类其余切实代码,供我们参照他事他说加以考察,具体内容如下 /* (程序...

/*学生信息管理系统,实现学生信息: 
 *增加 int[] a=new int[9] 
 *删除 
 *查找 
 *更改 
 */ 
import java.util.Scanner;//导入java输入流 
import java.lang.*; 
import java.io.*; 
class Student 
{ 
  private static Student[] s=new Student[2]; 
  int n=0; 
  private String name; 
  private int num; 
  private String classAge; 

  public void judge()throws IOException 
  { 
    int i; 
    char ch; 
    String str; 
    Scanner In=new Scanner(System.in); 
    if(n==0) 
    { 
      System.out.print("你还没有录入任何学生,是否录入(Y/N):"); 
      str=In.next(); 
      ch=str.charAt(0); 
      while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
      { 
        System.out.print("输入有误,请重新输入:"); 
        str=In.next(); 
        ch=str.charAt(0); 
      } 
      if(ch=='Y'||ch=='y') 
      { 
        this.add(); 
      } 
      if(ch=='N'||ch=='n') 
      { 
        this.menu(); 
      } 
    } 
  } 

  public void menu()throws IOException//定义菜单函数 
  { 
    int a;//定义switch语句变量 
    Scanner in=new Scanner(System.in);//实例化输入流对象 
    System.out.println("*********学生信息管理系统功能表*********"); 
    System.out.println("*****      1.增加       *****"); 
    System.out.println("*****      2.显示       *****"); 
    System.out.println("*****      3.修改       *****"); 
    System.out.println("*****      4.删除       *****"); 
    System.out.println("*****      5.查看       *****"); 
    System.out.println("*****      0.退出       *****"); 
    System.out.println("****************************************"); 
    System.out.print("请选择(0~5):"); 
    a=in.nextInt(); 
    while(a<0||a>5) 
    { 
      System.out.print("输入超出范围,请重新输入:"); 
      a=in.nextInt(); 
    } 
    switch(a) 
    { 
      case 1:this.add();break; 
      case 2:this.show();break; 
      case 3:this.modif();break; 
      case 4:this.delete();break; 
      case 5:this.look();break; 
      case 0:System.exit(0);break; 
    }       
  } 

  public void add()throws IOException//定义增加函数 
  { 
    String str,str1,str2; 
    int i,num1,t=1; 
    char ch,ch1; 
    FileWriter fw=new FileWriter("F://javaFile//student.txt",true); 
    fw.write("       录入的学生信息列表rnrn学号   姓名   班级rn"); 
    Scanner In=new Scanner(System.in); 
    while(t==1) 
    { 
      System.out.print("请输入学生学号:"); 
      num1=In.nextInt(); 
      for(i=0;i<n;i++) 
      { 
        while(s[i].num==num1) 
        { 
          System.out.println("已存在此学号,请重新输入"); 
          System.out.print("请输入学号:"); 
          num1=In.nextInt(); 
        } 
      } 
      s[n].num=num1; 
      str2=String.valueOf(num1); 
      fw.write(str2+"  "); 
      System.out.println(); 
      System.out.print("请输入学生姓名:"); 
      s[n].name=In.next(); 
      fw.write(s[n].name+"   "); 
      System.out.println(); 
      System.out.print("请输入学生班级:"); 
      s[n].classAge=In.next(); 
      fw.write(s[n].classAge+"rn"); 
      ++n; 
      fw.close();  
      System.out.println(); 
      System.out.print("是否继续添加(Y/N)"); 
      str=In.next(); 
      ch=str.charAt(0); 
      while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y') 
      { 
        System.out.print("输入有误,请重新输入:"); 
        str=In.next(); 
        ch=str.charAt(0); 
      } 
      if(ch=='N'||ch=='n') 
      { 
        break; 
      } 
    } 
    System.out.println(); 
    System.out.print("是否返回主菜单(Y/N)"); 
    str1=In.next(); 
    ch1=str1.charAt(0); 
    while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n') 
    { 
      System.out.print("输入有误,请重新输入:"); 
      str1=In.next(); 
      ch1=str1.charAt(0); 
    } 
    if(ch1=='Y'||ch1=='y') 
    { 
      this.menu(); 
    } 
    if(ch1=='N'||ch1=='n') 
    { 
      System.out.println("正在退出...谢谢使用!"); 
      System.exit(0); 
    } 
  } 

  public void show()throws IOException 
  { 
    int i; 
    this.judge();   
    System.out.println("本次操作共录入"+n+"位学生!"); 
    System.out.println("你录入的学生信息如下:"); 
    System.out.println(); 
    System.out.println("学号tt姓名t班级"); 
    for(i=0;i<n;i++)             
    { 
      System.out.println(s[i].num+"    "+s[i].name+"   "+s[i].classAge); 
    } 
    System.out.println("系统返回主菜单!"); 
    this.menu(); 
  } 

  public void delete()throws IOException//删除信息功能实现 注:本功能暂时不具备可扩展性 
  { 
    this.judge(); 
    int j=0,t=0,k=0,num1; 
    char ch; 
    String str; 
    Scanner pin=new Scanner(System.in); 
    System.out.print("请输入要删除的学号:"); 
    num1=pin.nextInt(); 
    for(j=0;j<n;j++) 
    { 
      if(s[j].num==num1) 
      { 
        k=1; 
        t=j; 
      } 
    } 
    if(k==0) 
    { 
      System.out.println("对不起!你要删除的学号不存在!"); 
      System.out.println("系统将返回主菜单!"); 
      this.menu(); 
    } 
    if(k==1) 
    { 
      System.out.println("你要删除的学生信息如下:");//打印管理员要删除的学生信息 
      System.out.println("学号t姓名t班级");//本功能暂时不备扩展性 
      System.out.println(s[t].num+"   "+s[t].name+"   "+s[t].classAge); 
      System.out.println(); 
      System.out.print("你确定要删除(Y/N):"); 
      str=pin.next(); 
      ch=str.charAt(0); 
      while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
      { 
        System.out.print("输入有误,请重新输入:"); 
        str=pin.next(); 
        ch=str.charAt(0); 
      } 
      if(ch=='N'||ch=='n') 
      { 
        System.out.println(); 
        System.out.println("系统返回主菜单!"); 
        this.menu(); 
      } 
      if(ch=='Y'||ch=='y') 
      { 
        for(j=t;j<n-1;j++) 
        { 
          s[j]=s[j+1]; 
        } 
        n--; 
        System.out.println("数据成功删除!"); 
        System.out.println("系统返回主菜单!"); 
        this.menu(); 
      } 
    } 
  } 

  public void look()throws IOException 
  { 
    FileReader fr=new FileReader("F://javaFile//student.txt"); 
    int a; 
    while((a=fr.read())!=-1) 
    { 
      System.out.print((char)a); 
    } 
    fr.close(); 
    System.out.println("系统返回主菜单!"); 
    System.out.println(); 
    this.menu(); 
  } 

  public void modif()throws IOException 
  { 
    this.judge(); 
    int j=0,t=0,k=0,num2,num3,moi,c=1; 
    char ch; 
    String str,str1,str2; 
    Scanner pin=new Scanner(System.in); 
    System.out.print("请输入要修改的学号:"); 
    num2=pin.nextInt(); 
    for(j=0;j<n;j++) 
    { 
      if(s[j].num==num2) 
      { 
        k=1; 
        t=j; 
      } 
    } 
    if(k==0) 
    { 
      System.out.println("对不起!你要修改的学号不存在!"); 
      System.out.println("系统将返回主菜单!"); 
      this.menu(); 
    } 
    if(k==1) 
    { 
      System.out.println("你要修改的学生信息如下:");//打印管理员要删除的学生信息 
      System.out.println("学号t姓名t班级");//本功能暂时不备扩展性 
      System.out.println(s[t].num+"   "+s[t].name+"   "+s[t].classAge); 
      System.out.println(); 
      System.out.print("你确定要修改(Y/N):"); 
      str=pin.next(); 
      ch=str.charAt(0); 
      while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
      { 
        System.out.print("输入有误,请重新输入:"); 
        str=pin.next(); 
        ch=str.charAt(0); 
      } 
      if(ch=='N'||ch=='n') 
      { 
        System.out.println(); 
        System.out.println("系统返回主菜单!"); 
        this.menu(); 
      } 
      while(c==1) 
      { 
        if(ch=='Y'||ch=='y') 
        { 
          System.out.println("****************************************"); 
          System.out.println("*****     1.修改学号      *****"); 
          System.out.println("*****     2.修改班级      *****"); 
          System.out.println("*****     3.修改姓名      *****"); 
          System.out.println("****************************************"); 
          System.out.print("请选择:"); 
          moi=pin.nextInt(); 
          switch(moi) 
          { 
            case 1:System.out.print("请输入新的学号:");num3=pin.nextInt();s[t].num=num3;break; 
            case 2:System.out.print("请输入新的班级:");str1=pin.next();s[t].classAge=str1;break; 
            case 3:System.out.print("请输入新的姓名:");str2=pin.next();s[t].name=str2;break; 
          } 
          System.out.println("数据已成功修改!"); 
        } 
        System.out.print("是否继续修改(Y/N)"); 
        str=pin.next(); 
        ch=str.charAt(0); 
        System.out.println(); 
        while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') 
        { 
          System.out.print("输入有误,请重新输入:"); 
          str=pin.next(); 
          ch=str.charAt(0); 
        } 
        if(ch=='N'||ch=='n') 
        { 
          break; 
        } 
      }   
    } 
    System.out.println(); 
    System.out.println("系统返回主菜单!"); 
    this.menu(); 
  } 

  public static void main(String[] args)throws IOException 
  {   
    Student stu=new Student(); 
    for(int i=0;i<2;i++) 
    { 
      s[i]=new Student(); 
    } 
    stu.menu(); 
  } 
} 

本文由杏彩发布,转载请注明来源

关键词: