Advertisement
Lowe576

gui

May 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. package Library;
  2.  
  3. /**
  4. *
  5. * @author Lowe
  6. */
  7. import java.awt.*;
  8. import java.awt.event.*;
  9. import javax.swing.*;
  10. public class Gui {
  11. private JFrame frame = new JFrame("Library");
  12. private JPanel background, centerPanel,southPanel;
  13. private JLabel l_isbnNo,l_title,l_rebound,l_lend,l_storage;
  14. private JTextField tf_isbnNo, tf_title, tf_rebound,tf_lend,tf_storage;
  15. private JButton b_find,b_rebound,b_lend,b_clear,b_addBook;
  16. private Book findBook;
  17. private Library libraryL;
  18.  
  19.  
  20. public Gui(Library l){
  21. libraryL = l;
  22. background = new JPanel();
  23. background.setLayout(new BorderLayout());
  24. centerPanel = new JPanel();
  25. background.setBorder(BorderFactory.createLineBorder(Color.RED,9, false));
  26.  
  27. centerPanel.setLayout((new GridLayout(5,2)));
  28. southPanel = new JPanel();
  29. southPanel.setLayout((new GridLayout(3,2)));
  30. l_isbnNo = new JLabel("isbn: ");
  31. l_title = new JLabel("title:");
  32. l_rebound = new JLabel ("return book:");
  33. l_lend = new JLabel("lend book:");
  34. l_storage = new JLabel("storage:");
  35. b_find = new JButton("Find book");
  36. b_rebound = new JButton("Return book");
  37. b_lend = new JButton("Lend book");
  38. b_clear = new JButton("Clear");
  39. b_addBook = new JButton("Add book");
  40. southPanel.add(b_rebound);
  41. southPanel.add(b_find);
  42. southPanel.add(b_lend);
  43. southPanel.add(b_clear);
  44. southPanel.add(b_addBook);
  45.  
  46.  
  47. tf_isbnNo= new JTextField(12);
  48. tf_title = new JTextField(12);
  49. tf_rebound = new JTextField(12);
  50. tf_lend = new JTextField(12);
  51. tf_storage = new JTextField(12);
  52. centerPanel.add(l_isbnNo);
  53. centerPanel.add(tf_isbnNo);
  54. centerPanel.add(l_title);
  55. centerPanel.add(tf_title);
  56. centerPanel.add(l_storage);
  57. centerPanel.add(tf_storage);
  58. centerPanel.add(l_rebound);
  59. centerPanel.add(tf_rebound);
  60. centerPanel.add(l_lend);
  61. centerPanel.add(tf_lend);
  62. background.add(centerPanel, BorderLayout.CENTER);
  63. background.add(southPanel, BorderLayout.SOUTH);
  64. frame.setContentPane(background);
  65. frame.pack();
  66. frame.setVisible(true);
  67. ClearHandler cl = new ClearHandler();
  68. FH fh = new FH();
  69.  
  70. this.b_clear.addActionListener(cl);
  71. this.b_lend.addActionListener(new WH());
  72. this.b_rebound.addActionListener(new DH());
  73. this.b_find.addActionListener(fh);
  74. //this.b_addBook.addActionListener(new Create());
  75. this.libraryL = libraryL;
  76.  
  77. }
  78. private class ClearHandler implements ActionListener{
  79. public void actionPerformed(ActionEvent ae){
  80. tf_isbnNo.setText("");
  81. tf_title.setText("");
  82. tf_rebound.setText("");
  83. tf_lend.setText("");
  84. tf_storage.setText("");
  85.  
  86. }
  87. }
  88. //private class DepositHandler implements ActionListener{
  89. //public void actionePerformed(ActionEvent ae){
  90. // double amount = Double.parseDouble(tf_deposit.getText());
  91. //foundAcc.deposit(amount);
  92. //tf_balance.setText(""+ foundAcc.balance)
  93. // System.out.println("deposit");
  94. //}
  95. //}
  96.  
  97. private class WH implements ActionListener{
  98. public void actionPerformed(ActionEvent ae){
  99. System.out.println("");
  100. String sWithdraw = tf_lend.getText();
  101. double amount = Double.parseDouble(sWithdraw);
  102. findBook.withdraw(amount);
  103. tf_storage.setText("" + findBook.storage());
  104.  
  105. }
  106. }
  107. private class DH implements ActionListener{
  108. public void actionPerformed(ActionEvent ae){
  109. System.out.println("");
  110. String sRebound = tf_rebound.getText();
  111. double amount = Double.parseDouble(sRebound);
  112. findBook.rebound(amount);
  113. tf_storage.setText("" + findBook.storage());
  114. System.out.println("Deposit" + amount);
  115. }
  116. // private class FL implements ActionListener{
  117. // public void actionPerformed(ActionEvent ae){
  118. // String accNo = tf_accountNo.getText();
  119. // foundAcc = banken.findAccount(Integer.parseInt(accNo));
  120. // String holder = founcAcc.holder();
  121. //double balance = foundAcc.holder();
  122. // tf_balance.setText(""+balance);
  123.  
  124. //}
  125. }
  126. private class FH implements ActionListener{
  127. public void actionPerformed(ActionEvent ae){
  128. System.out.println("");
  129. String sIsbnNo = tf_isbnNo.getText();
  130. int accNo = 0;
  131. try{
  132. accNo = Integer.parseInt(sIsbnNo);
  133.  
  134. }catch (NumberFormatException nfe){
  135. JOptionPane.showMessageDialog(frame, "skriv in siffror som kontonummer");
  136.  
  137. return;}
  138. Book findBook = libraryL.findBook("isbnNo");
  139. if(findBook!=null){
  140. tf_title.setText(findBook.title());
  141. tf_storage.setText(""+findBook.storage());
  142. }else JOptionPane.showMessageDialog(frame, "kontot finns inte! ");
  143. }
  144. }
  145. private class AddBook implements ActionListener{
  146. public void actionPerformed(ActionEvent ae){
  147. System.out.println("Create");
  148. String title = tf_title.getText();
  149. double amount = Double.parseDouble(tf_rebound.getText());
  150. Book create = new Book(title);
  151. tf_isbnNo.setText("" + create.isbnNo());
  152. libraryL.addBook(create);
  153. tf_rebound.setText("");
  154. tf_storage.setText("" + create.storage());
  155.  
  156. }
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement