Advertisement
Lowe576

Untitled

May 30th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. package library;
  2.  
  3. /**
  4. *
  5. * @author Lowe
  6. */
  7. public class Book {
  8. private int storage;
  9. private String isbn;
  10. private String title;
  11. private static int counter = 1000;
  12.  
  13. public Book( String title, String isbn, int initStorage){
  14. this.title = title;
  15. this.isbn= isbn;
  16. this.storage = storage;
  17. }
  18.  
  19. public void returnB(int amount){
  20. this.storage += amount;
  21. }
  22. public void lend(int amount){
  23. if(storage > amount){
  24. this.storage -= amount;
  25. }
  26. }
  27.  
  28. public int storage(){
  29. return storage;
  30. }
  31.  
  32. public String isbn(){
  33. return isbn;
  34. }
  35.  
  36. public String title(){
  37. return title;
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. package library;
  46.  
  47. import java.util.*;
  48.  
  49. /**
  50. *
  51. * @author Lowe
  52. */
  53. public class Library {
  54. private final ArrayList books = new ArrayList();
  55.  
  56. /**
  57. * @param args the command line arguments
  58. */
  59. public void addBook(Book b){
  60. books.add(b);
  61. }
  62.  
  63.  
  64. public Book findBook(String isbn){
  65.  
  66. for(int i=0; i<books.size() ; i++){
  67. Book temp = (Book)books.get(i);
  68.  
  69. if(temp.isbn()==isbn){
  70. return temp;
  71. }
  72. }
  73. return null;
  74. }
  75.  
  76. }
  77.  
  78.  
  79.  
  80. package library;
  81.  
  82. /**
  83. *
  84. * @author Lowe
  85. */
  86. public class LibrarySystem {
  87.  
  88. public static void main(String[] args){
  89.  
  90. Library libraryN = new Library();
  91.  
  92. Gui gui = new Gui(libraryN);
  93.  
  94. }
  95. }
  96.  
  97.  
  98.  
  99.  
  100. package library;
  101.  
  102. /**
  103. *
  104. * @author Lowe
  105. */
  106. import java.awt.*;
  107. import java.awt.event.*;
  108. import javax.swing.*;
  109. import java.io.*;
  110.  
  111. public class Gui {
  112.  
  113. private JFrame frame = new JFrame("Bibblan");
  114. private JPanel background, centerPanel, southPanel;
  115. private JLabel l_isbn,l_title, l_reclaim,l_lend,l_storage;
  116. private JTextField tf_isbn,tf_title, tf_reclaim,tf_lend,tf_storage;
  117. private JButton b_find,b_reclaim,b_lend,b_clear,b_newBook,b_save,b_load;
  118. private Book findB;
  119. private Library libraryN;
  120.  
  121.  
  122. public Gui(Library l){
  123. libraryN = l;
  124.  
  125. background = new JPanel();
  126. background.setLayout((new BorderLayout()));
  127. centerPanel = new JPanel();
  128. background.setBorder(BorderFactory.createLineBorder(Color.BLUE,9,false));
  129.  
  130. centerPanel.setLayout((new GridLayout(5,2)));
  131. southPanel = new JPanel();
  132. southPanel.setLayout((new GridLayout(3,2)));
  133.  
  134. b_find = new JButton("find");
  135. b_reclaim = new JButton("return");
  136. b_lend = new JButton("lend");
  137. b_clear = new JButton("clear");
  138. b_newBook = new JButton("Add");
  139. b_save = new JButton("save");
  140. b_load = new JButton("load");
  141.  
  142. southPanel.add(b_find);
  143. southPanel.add(b_reclaim);
  144. southPanel.add(b_lend);
  145. southPanel.add(b_clear);
  146. southPanel.add(b_newBook);
  147. southPanel.add(b_save);
  148. southPanel.add(b_load);
  149.  
  150. l_isbn = new JLabel("isbn:");
  151. l_title = new JLabel("title:");
  152. l_reclaim = new JLabel("return:");
  153. l_lend = new JLabel("lend:");
  154. l_storage = new JLabel("storage:");
  155.  
  156. tf_isbn = new JTextField(12);
  157. tf_title = new JTextField(12);
  158. tf_reclaim = new JTextField(12);
  159. tf_lend = new JTextField(12);
  160. tf_storage = new JTextField(12);
  161.  
  162. centerPanel.add(l_isbn);
  163. centerPanel.add(tf_isbn);
  164. centerPanel.add(l_title);
  165. centerPanel.add(tf_title);
  166. centerPanel.add(l_reclaim);
  167. centerPanel.add(tf_reclaim);
  168. centerPanel.add(l_lend);
  169. centerPanel.add(tf_lend);
  170. centerPanel.add(l_storage);
  171. centerPanel.add(tf_storage);
  172.  
  173. frame.setContentPane(background);
  174. frame.pack();
  175. frame.setVisible(true);
  176.  
  177. ClearHandler cl = new ClearHandler();
  178. FindHandler fh = new FindHandler();
  179.  
  180. this.b_clear.addActionListener(cl);
  181. this.b_lend.addActionListener(new LE());
  182. this.b_reclaim.addActionListener(new RE());
  183. this.b_find.addActionListener(fh);
  184. this.b_addNB.addActionListener(new addNB());
  185. this.libraryN = libraryN;
  186.  
  187. }
  188.  
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement