Advertisement
Lowe576

library

May 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. package Library;
  2.  
  3. /**
  4. *
  5. * @author Lowe
  6. */
  7. public class LibrarySystem {
  8.  
  9. /**
  10. * @param args the command line arguments
  11. */
  12. public static void main(String[] args) {
  13. // TODO code application logic here
  14. Book b1 = new Book("Tures Γ€ventyr", 4500);
  15. Book b2 = new Book("Solskensdalen", 42332);
  16. Book b3 = new Book("Wikipedia vol 1", 42342);
  17.  
  18. Library LibraryN =new Library();
  19.  
  20. LibraryN.addBook(b1);
  21. LibraryN.addBook(b2);
  22. LibraryN.addBook(b3);
  23.  
  24.  
  25.  
  26. Gui gui=new Gui(LibraryN);
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33. package Library;
  34.  
  35. /**
  36. *
  37. * @author Lowe
  38. */
  39. import java.util.*;
  40. public class Library {
  41. private ArrayList books = new ArrayList();
  42.  
  43. public void addBook (Book b){
  44. books.add(b);
  45. }
  46. public Book findBook(String isbnNo){
  47. for(int i = 0; i < books.size(); i++){
  48. Book temp = (Book)books.get(i);
  49. if(temp.isbnNo()== isbnNo){
  50. return temp;
  51. }
  52. }
  53. return null;
  54. }
  55.  
  56. }
  57.  
  58.  
  59.  
  60. package Library;
  61.  
  62. /**
  63. *
  64. * @author Lowe
  65. */
  66. public class Book {
  67. private int storage;
  68. private String isbnNo;
  69. private String title;
  70. private static int counter = 1000;
  71.  
  72. public Book(String title, int Storage){
  73. this.title = title;
  74. this.storage = Storage;
  75. }
  76.  
  77. public void rebound(double amount){
  78. this.storage += amount;
  79. }
  80.  
  81. public int storage(){
  82. return storage;}
  83. public void withdraw( double amount){
  84. if(storage >= amount){
  85. this.storage -= amount;
  86. }
  87. }
  88. public String isbnNo(){
  89. return isbnNo;
  90. }
  91. public String title(){
  92. return title;
  93. }
  94. public String toString(){
  95. return "name: " + title + "\n " + "accountNo:" + isbnNo + "\n " + "balance: " + storage +"\n";
  96. }
  97.  
  98. }
  99.  
  100.  
  101.  
  102. package Library;
  103.  
  104. /**
  105. *
  106. * @author Lowe
  107. */
  108. import java.awt.*;
  109. import java.awt.event.*;
  110. import javax.swing.*;
  111. public class Gui {
  112. private JFrame frame = new JFrame("Library");
  113. private JPanel background, centerPanel,southPanel;
  114. private JLabel l_isbnNo,l_title,l_rebound,l_lend,l_storage;
  115. private JTextField tf_isbnNo, tf_title, tf_rebound,tf_lend,tf_storage;
  116. private JButton b_find,b_rebound,b_lend,b_clear,b_addBook;
  117. private Book findBook;
  118. private Library libraryL;
  119.  
  120.  
  121. public Gui(Library l){
  122. libraryL = l;
  123. background = new JPanel();
  124. background.setLayout(new BorderLayout());
  125. centerPanel = new JPanel();
  126. background.setBorder(BorderFactory.createLineBorder(Color.RED,9, false));
  127.  
  128. centerPanel.setLayout((new GridLayout(5,2)));
  129. southPanel = new JPanel();
  130. southPanel.setLayout((new GridLayout(3,2)));
  131. l_isbnNo = new JLabel("accountNo: ");
  132. l_title = new JLabel("name:");
  133. l_rebound = new JLabel ("deposit:");
  134. l_lend = new JLabel("withdraw:");
  135. l_storage = new JLabel("balance:");
  136. b_find = new JButton("FIND");
  137. b_rebound = new JButton("Deposit");
  138. b_lend = new JButton("Witdraw");
  139. b_clear = new JButton("CLEAR");
  140. b_addBook = new JButton("CREATE");
  141. southPanel.add(b_rebound);
  142. southPanel.add(b_find);
  143. southPanel.add(b_lend);
  144. southPanel.add(b_clear);
  145. southPanel.add(b_addBook);
  146.  
  147.  
  148. tf_isbnNo= new JTextField(12);
  149. tf_title = new JTextField(12);
  150. tf_rebound = new JTextField(12);
  151. tf_lend = new JTextField(12);
  152. tf_storage = new JTextField(12);
  153. centerPanel.add(l_isbnNo);
  154. centerPanel.add(tf_isbnNo);
  155. centerPanel.add(l_title);
  156. centerPanel.add(tf_title);
  157. centerPanel.add(l_storage);
  158. centerPanel.add(tf_storage);
  159. centerPanel.add(l_rebound);
  160. centerPanel.add(tf_rebound);
  161. centerPanel.add(l_lend);
  162. centerPanel.add(tf_lend);
  163. background.add(centerPanel, BorderLayout.CENTER);
  164. background.add(southPanel, BorderLayout.SOUTH);
  165. frame.setContentPane(background);
  166. frame.pack();
  167. frame.setVisible(true);
  168. ClearHandler cl = new ClearHandler();
  169. FH fh = new FH();
  170.  
  171. this.b_clear.addActionListener(cl);
  172. this.b_lend.addActionListener(new WH());
  173. this.b_rebound.addActionListener(new DH());
  174. this.b_find.addActionListener(fh);
  175. //this.b_addBook.addActionListener(new Create());
  176. this.libraryL = libraryL;
  177.  
  178. }
  179. private class ClearHandler implements ActionListener{
  180. public void actionPerformed(ActionEvent ae){
  181. tf_isbnNo.setText("");
  182. tf_title.setText("");
  183. tf_rebound.setText("");
  184. tf_lend.setText("");
  185. tf_storage.setText("");
  186.  
  187. }
  188. }
  189. //private class DepositHandler implements ActionListener{
  190. //public void actionePerformed(ActionEvent ae){
  191. // double amount = Double.parseDouble(tf_deposit.getText());
  192. //foundAcc.deposit(amount);
  193. //tf_balance.setText(""+ foundAcc.balance)
  194. // System.out.println("deposit");
  195. //}
  196. //}
  197.  
  198. private class WH implements ActionListener{
  199. public void actionPerformed(ActionEvent ae){
  200. System.out.println("");
  201. String sWithdraw = tf_lend.getText();
  202. double amount = Double.parseDouble(sWithdraw);
  203. findBook.withdraw(amount);
  204. tf_storage.setText("" + findBook.storage());
  205.  
  206. }
  207. }
  208. private class DH implements ActionListener{
  209. public void actionPerformed(ActionEvent ae){
  210. System.out.println("");
  211. String sRebound = tf_rebound.getText();
  212. double amount = Double.parseDouble(sRebound);
  213. findBook.rebound(amount);
  214. tf_storage.setText("" + findBook.storage());
  215. System.out.println("Deposit" + amount);
  216. }
  217. // private class FL implements ActionListener{
  218. // public void actionPerformed(ActionEvent ae){
  219. // String accNo = tf_accountNo.getText();
  220. // foundAcc = banken.findAccount(Integer.parseInt(accNo));
  221. // String holder = founcAcc.holder();
  222. //double balance = foundAcc.holder();
  223. // tf_balance.setText(""+balance);
  224.  
  225. //}
  226. }
  227. private class FH implements ActionListener{
  228. public void actionPerformed(ActionEvent ae){
  229. System.out.println("");
  230. String sIsbnNo = tf_isbnNo.getText();
  231. int accNo = 0;
  232. try{
  233. accNo = Integer.parseInt(sIsbnNo);
  234.  
  235. }catch (NumberFormatException nfe){
  236. JOptionPane.showMessageDialog(frame, "skriv in siffror som kontonummer");
  237.  
  238. return;}
  239. Book findBook = libraryL.findBook("isbnNo");
  240. if(findBook!=null){
  241. tf_title.setText(findBook.title());
  242. tf_storage.setText(""+findBook.storage());
  243. }else JOptionPane.showMessageDialog(frame, "kontot finns inte! ");
  244. }
  245. }
  246. private class AddBook implements ActionListener{
  247. public void actionPerformed(ActionEvent ae){
  248. System.out.println("Create");
  249. String title = tf_title.getText();
  250. double amount = Double.parseDouble(tf_rebound.getText());
  251. Book create = new Book(title);
  252. tf_isbnNo.setText("" + create.isbnNo());
  253. libraryL.addBook(create);
  254. tf_rebound.setText("");
  255. tf_storage.setText("" + create.storage());
  256.  
  257. }
  258. }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement