Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.93 KB | None | 0 0
  1. package bookborrowing;
  2.  
  3. import javax.swing.*;   //JComponents
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. public class BookBorrowing extends JFrame implements ActionListener {
  9.        //declaring JComponents
  10.  
  11.             JLabel lblTitle,lBG;
  12.  
  13.             JButton bAddBook,bViewBook,bReturnBook,bIssueBook,
  14.                     bLogout;
  15.        // issuebook is my Borrowed Book
  16.            
  17.            JPanel panel, addbook, viewbook, returnbook, issuebook;
  18.       //construct / instantiate conponents
  19.  
  20.  
  21.           public BookBorrowing() {
  22.  
  23.  
  24.            JFrame frame = new JFrame("Book Borrowing System");
  25.  
  26.            panel = new JPanel();
  27.            panel.setLayout(null);
  28.            panel.setBackground(Color.YELLOW);
  29.            panel.setVisible(true);
  30.            
  31.            addbook = new JPanel();
  32.            addbook.setLayout(null);
  33.            addbook.setBackground(Color.YELLOW);
  34.            addbook.setVisible(false);
  35.            
  36.            issuebook = new JPanel();
  37.            issuebook.setLayout(null);
  38.            issuebook.setBackground(Color.YELLOW);
  39.            issuebook.setVisible(false);
  40.            
  41.            viewbook = new JPanel();
  42.            viewbook.setLayout(null);
  43.            viewbook.setBackground(Color.YELLOW);
  44.            viewbook.setVisible(false);
  45.            
  46.            returnbook = new JPanel();
  47.            returnbook.setLayout(null);
  48.            returnbook.setBackground(Color.YELLOW);
  49.            returnbook.setVisible(false);
  50.          
  51.            //Container c = getContentPane();
  52.             JLabel lblBG = new JLabel();
  53.             lblBG.setBackground(Color.YELLOW);
  54.  
  55.  
  56.            lblTitle = new JLabel(" BOOK BORROWING SYSTEM ");
  57.            lblTitle.setFont(new Font("Arial Black",Font.BOLD,27));
  58.            lblTitle.setForeground(Color.BLACK);
  59.          
  60.            
  61.            bAddBook = new JButton("Add Book/s");
  62.            bAddBook.setBackground(new Color(204,0,0));
  63.            bAddBook.setFont(new Font("Calibri",Font.BOLD,20));
  64.            bAddBook.setForeground(Color.WHITE);
  65.            bViewBook = new JButton("View Book/s");
  66.            bViewBook.setBackground(new Color(204,0,0));
  67.            bViewBook.setFont(new Font("Calibri",Font.BOLD,20));
  68.            bViewBook.setForeground(Color.WHITE);
  69.            bReturnBook = new JButton("Return Book/s");
  70.            bReturnBook.setBackground(new Color(204,0,0));
  71.            bReturnBook.setFont(new Font("Calibri",Font.BOLD,20));
  72.            bReturnBook.setForeground(Color.WHITE);
  73.            bIssueBook = new JButton("Borrow Book/s");
  74.            bIssueBook .setBackground(new Color(204,0,0));
  75.            bIssueBook .setFont(new Font("Calibri",Font.BOLD,20));
  76.            bIssueBook .setForeground(Color.WHITE);
  77.            bLogout = new JButton("LOG OUT");
  78.            bLogout .setBackground(new Color(204,0,0));
  79.            bLogout .setFont(new Font("Calibri",Font.BOLD,20));
  80.            bLogout .setForeground(Color.WHITE);
  81.  
  82.          
  83.        //Placing Components on the JFrame
  84.        //setBound(x,y,width,height)=>positioning
  85.  
  86.    
  87.        //JLabel positioning
  88.        panel.add(lblTitle);
  89.        lblTitle.setBounds(300,80,500,40);
  90.        
  91.  
  92.        //JButton positioning
  93.        
  94.        panel.add(bAddBook);
  95.        bAddBook.setBounds(440,200,180,40);
  96.        panel.add(bViewBook);
  97.        bViewBook.setBounds(440,280,180,40);
  98.        panel.add(bReturnBook);
  99.        bReturnBook.setBounds(440,360,180,40);
  100.        panel.add(bIssueBook);
  101.        bIssueBook.setBounds(440,440,180,40);
  102.        panel.add(bLogout);
  103.        bLogout.setBounds(440,520,180,40);
  104.        
  105.      
  106.        //button actionlistener
  107.      
  108.        bAddBook.addActionListener(this);
  109.        bViewBook.addActionListener(this);
  110.        bReturnBook.addActionListener(this);
  111.        bIssueBook.addActionListener(this);
  112.        bLogout.addActionListener(this);
  113.      
  114.             frame.add(panel);
  115.             frame.setSize(1100,900);
  116.        frame.setVisible( true );
  117.        frame.setResizable(false);
  118.        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  119.            
  120.            
  121.  
  122.  
  123.     }//end of constructor
  124.  
  125.  
  126.     public void actionPerformed (ActionEvent e ) {
  127.        
  128.         if (e.getSource()== bAddBook){
  129.             panel.setVisible(false);
  130.             addbook.setVisible(true);
  131.         }
  132.        
  133.          if (e.getSource()== bViewBook){
  134.             panel.setVisible(false);
  135.             viewbook.setVisible(true);
  136.         }
  137.        
  138.          if (e.getSource()== bReturnBook){
  139.             panel.setVisible(false);
  140.             returnbook.setVisible(true);
  141.         }
  142.          
  143.         if (e.getSource()== bIssueBook){
  144.             panel.setVisible(false);
  145.             issuebook.setVisible(true);
  146.         }
  147.        
  148.      
  149.     }//end of action performed
  150.    
  151.     public static void main(String[] args) {
  152.        
  153.        BookBorrowing BB = new BookBorrowing();
  154.        
  155.        
  156.     }    // main method begins execution of Java application    
  157.    
  158. }  // end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement