Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Library;
- /**
- *
- * @author Lowe
- */
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Gui {
- private JFrame frame = new JFrame("Library");
- private JPanel background, centerPanel,southPanel;
- private JLabel l_isbnNo,l_title,l_rebound,l_lend,l_storage;
- private JTextField tf_isbnNo, tf_title, tf_rebound,tf_lend,tf_storage;
- private JButton b_find,b_rebound,b_lend,b_clear,b_addBook;
- private Book findBook;
- private Library libraryL;
- public Gui(Library l){
- libraryL = l;
- background = new JPanel();
- background.setLayout(new BorderLayout());
- centerPanel = new JPanel();
- background.setBorder(BorderFactory.createLineBorder(Color.RED,9, false));
- centerPanel.setLayout((new GridLayout(5,2)));
- southPanel = new JPanel();
- southPanel.setLayout((new GridLayout(3,2)));
- l_isbnNo = new JLabel("isbn: ");
- l_title = new JLabel("title:");
- l_rebound = new JLabel ("return book:");
- l_lend = new JLabel("lend book:");
- l_storage = new JLabel("storage:");
- b_find = new JButton("Find book");
- b_rebound = new JButton("Return book");
- b_lend = new JButton("Lend book");
- b_clear = new JButton("Clear");
- b_addBook = new JButton("Add book");
- southPanel.add(b_rebound);
- southPanel.add(b_find);
- southPanel.add(b_lend);
- southPanel.add(b_clear);
- southPanel.add(b_addBook);
- tf_isbnNo= new JTextField(12);
- tf_title = new JTextField(12);
- tf_rebound = new JTextField(12);
- tf_lend = new JTextField(12);
- tf_storage = new JTextField(12);
- centerPanel.add(l_isbnNo);
- centerPanel.add(tf_isbnNo);
- centerPanel.add(l_title);
- centerPanel.add(tf_title);
- centerPanel.add(l_storage);
- centerPanel.add(tf_storage);
- centerPanel.add(l_rebound);
- centerPanel.add(tf_rebound);
- centerPanel.add(l_lend);
- centerPanel.add(tf_lend);
- background.add(centerPanel, BorderLayout.CENTER);
- background.add(southPanel, BorderLayout.SOUTH);
- frame.setContentPane(background);
- frame.pack();
- frame.setVisible(true);
- ClearHandler cl = new ClearHandler();
- FH fh = new FH();
- this.b_clear.addActionListener(cl);
- this.b_lend.addActionListener(new WH());
- this.b_rebound.addActionListener(new DH());
- this.b_find.addActionListener(fh);
- //this.b_addBook.addActionListener(new Create());
- this.libraryL = libraryL;
- }
- private class ClearHandler implements ActionListener{
- public void actionPerformed(ActionEvent ae){
- tf_isbnNo.setText("");
- tf_title.setText("");
- tf_rebound.setText("");
- tf_lend.setText("");
- tf_storage.setText("");
- }
- }
- //private class DepositHandler implements ActionListener{
- //public void actionePerformed(ActionEvent ae){
- // double amount = Double.parseDouble(tf_deposit.getText());
- //foundAcc.deposit(amount);
- //tf_balance.setText(""+ foundAcc.balance)
- // System.out.println("deposit");
- //}
- //}
- private class WH implements ActionListener{
- public void actionPerformed(ActionEvent ae){
- System.out.println("");
- String sWithdraw = tf_lend.getText();
- double amount = Double.parseDouble(sWithdraw);
- findBook.withdraw(amount);
- tf_storage.setText("" + findBook.storage());
- }
- }
- private class DH implements ActionListener{
- public void actionPerformed(ActionEvent ae){
- System.out.println("");
- String sRebound = tf_rebound.getText();
- double amount = Double.parseDouble(sRebound);
- findBook.rebound(amount);
- tf_storage.setText("" + findBook.storage());
- System.out.println("Deposit" + amount);
- }
- // private class FL implements ActionListener{
- // public void actionPerformed(ActionEvent ae){
- // String accNo = tf_accountNo.getText();
- // foundAcc = banken.findAccount(Integer.parseInt(accNo));
- // String holder = founcAcc.holder();
- //double balance = foundAcc.holder();
- // tf_balance.setText(""+balance);
- //}
- }
- private class FH implements ActionListener{
- public void actionPerformed(ActionEvent ae){
- System.out.println("");
- String sIsbnNo = tf_isbnNo.getText();
- int accNo = 0;
- try{
- accNo = Integer.parseInt(sIsbnNo);
- }catch (NumberFormatException nfe){
- JOptionPane.showMessageDialog(frame, "skriv in siffror som kontonummer");
- return;}
- Book findBook = libraryL.findBook("isbnNo");
- if(findBook!=null){
- tf_title.setText(findBook.title());
- tf_storage.setText(""+findBook.storage());
- }else JOptionPane.showMessageDialog(frame, "kontot finns inte! ");
- }
- }
- private class AddBook implements ActionListener{
- public void actionPerformed(ActionEvent ae){
- System.out.println("Create");
- String title = tf_title.getText();
- double amount = Double.parseDouble(tf_rebound.getText());
- Book create = new Book(title);
- tf_isbnNo.setText("" + create.isbnNo());
- libraryL.addBook(create);
- tf_rebound.setText("");
- tf_storage.setText("" + create.storage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement