1、#Java图书图书管理系统分析方案成都信息项目学院计算机学院课 程 实 验 报 告实验课程:Java程序设计实验项目:图书管理系统指导教师:汤蓉学生姓名:向浩学生学号:2018051020班 级:计科111班实验地点:6306上交时间:2018年1月12实验成绩:一、 源代码import java.io.*。 public class Book implements Serializable/书的基类 public String author。/作者 public String published。/出版商 public String nameOfBook。/书名 private int Bo
2、oknumbers = 200。 public Book( public Book(String author,String published,String nameofBook this.author = author。 this.published = published。 this.nameOfBook = nameofBook。 private void writeObject(ObjectOutputStream out throws IOException out.writeUTF(author。 out.writeUTF(published。 out.writeUTF(name
3、OfBook。 private void readObject(ObjectInputStream in throws IOException author=in.readUTF(。 published=in.readUTF(。 nameOfBook=in.readUTF(。 private boolean bool = false。 public synchronized void borrowBook( if(bool try wait(。/多线程通信机制 catch(InterruptedException e System.out.println(Book类出现异常。 else boo
4、l = false。 Booknumbers-。 System.out.println(目前图书馆的馆藏图书一共有+Booknumbers+册。 notify(。/其他的线程被唤醒 public synchronized void returnBook( if(bool try wait(。/多线程通信机制 catch(InterruptedException e System.out.println(Book类出现异常。 else bool = true。 Booknumbers+。 System.out.println(目前图书馆的馆藏图书一共有+Booknumbers+册。 notify
5、(。/通知其他的线程被唤醒 public class BorrowedBookOutOfLimitException extends Exception /借书的数量超过了规定最大的数量抛出的异常public class BorrowThread implements Runnable Book book。 public BorrowThread(Book Bo book = Bo。 public void run( try book.borrowBook(。 Thread.sleep(10。 catch(InterruptedException io System.out.println(B
6、orrowThread出现异常。 import java.awt.*。import java.awt.Event.*。 import java.awt.event.MouseEvent。import java.awt.event.MouseListener。public class Button1Handler implements MouseListener public void mouseClicked(MouseEvent e UserLogin tft = new UserLogin(。 public void mouseEntered(MouseEvent e / Picture.
7、lb3.setText(你已经可以进行单击操作。 public void mousePressed(MouseEvent e / Picture.lb3.setText(你已按下按钮!。 public void mouseRelesed(MouseEvent e Override public void mouseReleased(MouseEvent e / TODO Auto-generated method stub Override public void mouseExited(MouseEvent e / TODO Auto-generated method stub import
8、 java.awt.event.ActionEvent。import java.awt.event.ActionListener。public class Button2Handler implements ActionListener public void actionPerformed(ActionEvent e System.exit(0。 import java.awt.*。import java.awt.Event.*。 import java.awt.event.MouseEvent。import java.awt.event.MouseListener。import java.
9、io.IOException。public class Button5Handler implements MouseListener public void mouseClicked(MouseEvent e MainTest Main = new MainTest(。 public void mouseEntered(MouseEvent e / Picture.lb3.setText(你已经可以进行单击操作。 public void mousePressed(MouseEvent e / Picture.lb3.setText(你已按下按钮!。 public void mouseRele
10、sed(MouseEvent e Override public void mouseReleased(MouseEvent e / TODO Auto-generated method stub Override public void mouseExited(MouseEvent e / TODO Auto-generated method stub import java.awt.event.FocusEvent。import java.awt.event.FocusListener。public class focusHandler implements FocusListener p
11、ublic void focusGainded(FocusEvent e public void focusLost(FocusEvent e Object ob = e.getSource(。 if(ob=UserLogin.txtName。 / System.out.println(UserLogin.txtName.getText(。 if(ob=UserLogin.txtPass / System.out.println(UserLogin.txtPass.getText(。 Override public void focusGained(FocusEvent e / TODO Au
12、to-generated method stub import java.awt.event.KeyEvent。import java.awt.event.KeyListener。public class keyHandler implements KeyListener public void keyPressed(KeyEvent e Object ob = e.getSource(。 if(ob=UserLogin.txtName&(e.getKeyCode(=10 / System.out.println(UserLogin.txtName.getText(。 else if(ob=U
13、serLogin.txtName&(e.getKeyCode(=10 / System.out.println(UserLogin.txtPass.getText(。 public void keyReleased(KeyEvent e public void keyTyped(KeyEvent e import java.io.*。public class Library extends Student public static int nowBooknumber= 0。 public String nameOfLibrary = CUIT Library。 public static i
14、nt nowStudentNumber = 0。 public Student STUDENT。 public Book booK。 public Library( STUDENT=new Student30。 booK = new Book20。 public void AddNewBook( throws IOException,ClassNotFoundException boolean change = true。 String tomp1,tomp2,tomp3,tomp5。 tomp1 = new String(。 tomp2 = new String(。 tomp3 = new
15、String(。 tomp5 = new String(。 while(change +nowBooknumber。 System.out.println(请输入加入图书的作者:。 try tomp1 = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catch block e.printStackTrace(。 System.out.println(请输入加入图书书名:。 try tomp2 = MainTest.initiate2(。 catch (IOException e / TODO Auto-gene
16、rated catch block e.printStackTrace(。 System.out.println(请输入加入图书的出版商:。 try tomp3 = MainTest.initiate2(。 catch (IOException e e.printStackTrace(。 booKnowBooknumber = new Book(tomp1,tomp2,tomp3。 MainTest.oos1.writeObject(booKnowBooknumber。 System.out.print(请问你还需要继续加入学生吗?1代表继续添加其他代表退出。 try tomp5 = Main
17、Test.initiate2(。 catch (IOException e e.printStackTrace(。 int middle = Integer.parseInt(tomp5.trim(。 if(middle = 1 change = true。 else change = false。 public Book displayBookInformation( throws IOException, ClassNotFoundException int j = 0。 FileInputStream fis = new FileInputStream(C:AddNewBook.txt。
18、 ObjectInputStream ois = new ObjectInputStream(fis。 try while(true booKj = (Bookois.readObject(。 System.out.println(图书名称:+booKj.author+图书出版商:+booKj.published+图书书名:+booKj.nameOfBook。 +j。 catch(Exception e nowBooknumber = j。 if(nowBooknumber System.out.println(你暂时还没有添加图书的相关的信息。 return null。 return boo
19、K。 /注:下面这个方法和上面这个方法是一样的,我们只是为了能够在Student类查找的时候能够用得到 public Book displayBookInformation1( throws IOException, ClassNotFoundException int j = 0。 FileInputStream fis = new FileInputStream(C:AddNewBook.txt。 ObjectInputStream ois = new ObjectInputStream(fis。 try while(true booKj = (Bookois.readObject(。/
20、System.out.println(图书名称:+booKj.author+图书出版商:+booKj.published+图书书名:+booKj.nameOfBook。 +j。 catch(Exception e nowBooknumber = j。 if(nowBooknumber System.out.println(你暂时还没有添加图书的相关的信息。 return null。 return booK。 public void addNewReader( throws IOException,NotSerializableException boolean change = true。 S
21、tring tomp1,tomp2,tomp3,tomp4,tomp5,number = null。 tomp1 = new String(。 tomp2 = new String(。 tomp3 = new String(。 tomp4 = new String(。 tomp5 = new String(。 while(change +nowStudentNumber。 System.out.println(请输入加入学生的姓名:。 try tomp1 = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catc
22、h block e.printStackTrace(。 System.out.println(请输入加入学生的性别:。 try tomp2 = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catch block e.printStackTrace(。 System.out.println(请输入加入学生的出生年月:。 try tomp3 = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catch block e.printSta
23、ckTrace(。 System.out.println(请输入加入学生的专业:。 try tomp4 = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catch block e.printStackTrace(。 System.out.println(请输入加入学生的学号:。 try number = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catch block e.printStackTrace(。 STUDENTno
24、wStudentNumber= new Student(tomp1,tomp2,tomp3,tomp4,number。 MainTest.oos2.writeObject(STUDENTnowStudentNumber。 System.out.print(请问你还需要继续加入学生吗?1代表继续添加其他代表退出。 try tomp5 = MainTest.initiate2(。 catch (IOException e / TODO Auto-generated catch block e.printStackTrace(。 int middle = Integer.parseInt(tomp5
25、.trim(。 if(middle = 1 change = true。 else change = false。 public void displayReaderInformation( throws IOException, ClassNotFoundException int j = 0。 FileInputStream fis1 = new FileInputStream(C:AddNewReader.txt。 ObjectInputStream ois1 = new ObjectInputStream(fis1。 try while(true STUDENTj = (Student
26、ois1.readObject(。 System.out.println(学生学号:+STUDENTj.studentNum+学生专业 :+STUDENTj.major+学生姓名 :+STUDENTj.name+学生性别: +STUDENTj.gender+出生日期:+STUDENTj.birthDate。 +j。 catch(Exception io nowStudentNumber = j。 if(nowStudentNumber System.out.println(你暂时还没有添加读者的相关的信息。 return 。 public void modifyInformation( throws IOException, ClassNotFoundException boolean change = true,chn = true。 String tomp1,tomp2,tomp3,tomp4,tomp5,tomp6,tomp7。 tomp1 = new String(。 tomp2 = new String(。 tomp3 = new String(。 tomp4 = new String(。 tomp5 = new Str
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1