Dashboard

Dashboard

Above UI we are going to create by Awt for Showing dashboard in our Flight Booking System desktop application. For that first we create a window and configure its title, size and color. Here we are creating a window at Top Level so we can add this window at the top of any other window and a JPanel for adding more fields.

    
    //frame with control options
		dashboardFrame = new JFrame();
		Utils.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Flight Booking System");
		dashboardFrame.setResizable(false);
		
		Container frameContainer = dashboardFrame.getContentPane();
		frameContainer.setBackground(Color.gray);

		// Changeable According to What size of screen You Want?
		int containerWidth = windowWidth*94/100;
		int containerHeight = windowHeight*90/100;
		
		int panelWidth = containerWidth*98/100;
		int panelHeight = containerHeight*96/100;
		int posX = windowWidth / 2 - panelWidth / 2 ;
		int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;

		// frame without control options
		JPanel panel = new JPanel(); 
		panel.setLayout(null);//new BorderLayout()); 
		//panel.setOpaque(false);
		panel.setBackground(Color.decode("#FFFFFF")); 
		panel.setSize(new Dimension(panelWidth,panelHeight)); 
		panel.setLocation(posX, posY);
		frameContainer.add(panel);

    

After creation of window, we will add a canvas background.

    
        // for Rounded Background
		posX = windowWidth / 2 - containerWidth / 2 ;
		posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
		JComponent jcomponent = new RoundedBackground(posX, posY, containerWidth, containerHeight);
		jcomponent.setLayout(null);
		frameContainer.add(jcomponent, BorderLayout.CENTER);
		

    public class RoundedBackground extends JComponent {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int width, height,setX,setY;

    public RoundedBackground (int setX,int setY,int width, int height) {
    	this.width=width;
    	this.height=height;
    	this.setX=setX;
    	this.setY=setY;
    	
       setSize(width, height);
    }
	
    @Override
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.white);

        //g2.setStroke(new BasicStroke(2.0f));

        double x = setX;
        double y = setY;
        double w = width;
        double h = height;
        RoundRectangle2D round=new RoundRectangle2D.Double(x, y, w, h, 80, 80);
        g2.fill(round);

    }
}
    

Here we create heading in that we adding some JLabel, JSeparator and logout Button.

    
    
    // for heading Layout
		posY = panelHeight * 2/100;
		Font headingFont = new Font("Serif", Font.PLAIN, 25);
		// header
		//borderline = BorderFactory.createLineBorder(Color.black);
				
		JLabel heading_text = new JLabel("Flight Booking System");
		heading_text.setHorizontalAlignment(JLabel.CENTER);
		heading_text.setVerticalAlignment(JLabel.CENTER);
		heading_text.setBackground(Color.decode("#80c2b2"));
		heading_text.setForeground(Color.black);
		heading_text.setFont(headingFont);
		heading_text.setBounds(0,0, panelWidth, panelHeight / 9);
		panel.add(heading_text);
		
		headingFont = new Font("Serif", Font.PLAIN, 15);
		JLabel heading_text_minor = new JLabel("Dashboard");
		heading_text_minor.setHorizontalAlignment(JLabel.CENTER);
		heading_text_minor.setVerticalAlignment(JLabel.CENTER);
		heading_text_minor.setBackground(Color.decode("#80c2b2"));
		heading_text_minor.setForeground(Color.black);
		heading_text_minor.setFont(headingFont);
		heading_text_minor.setBounds(0,panelHeight*6/100, panelWidth, panelHeight / 9);
		panel.add(heading_text_minor);
				
		panel.add(Utils.getSeparator(0, panelHeight / 7, panelWidth, 5,"000000"));	
        
		panel.add(Utils.getSeparator(0, panelHeight*22/100, panelWidth, 5,"000000"));	

        
		headingFont = new Font("Serif", Font.PLAIN, 12);
		JLabel admin_text = new JLabel("Hi  "+AppConstant.STAFF_NAME);
		admin_text.setHorizontalAlignment(JLabel.LEFT);
		admin_text.setVerticalAlignment(JLabel.CENTER);
		admin_text.setBackground(Color.decode("#80c2b2"));
		admin_text.setForeground(Color.black);
		admin_text.setFont(headingFont);
		admin_text.setBounds(panelWidth*2/100,panelHeight*13/100, panelWidth/2, panelHeight / 9);
		panel.add(admin_text);
		
		panel.add(getLogoutButton(panelWidth, panelHeight));	

        
    

Here we define "LOGOUT" button and click functionality.

    
    private JButton getLogoutButton(int width, int height) {
		  
          logoutBtn = new JButton(new ImageIcon(((new ImageIcon("images/button40.png")).getImage()).getScaledInstance( width*16/100, height*6/100, java.awt.Image.SCALE_SMOOTH)));
          logoutBtn.setContentAreaFilled(false);
          logoutBtn.setBorder(null);
          logoutBtn.setText("LOGOUT");
          logoutBtn.setHorizontalTextPosition(JButton.CENTER);
          logoutBtn.setVerticalTextPosition(JButton.CENTER);
          logoutBtn.setBounds(width*83/100,(int) (height*14/100)+8, width*16/100, height*6/100); 
          logoutBtn.setFont(new java.awt.Font("Serif",1, 12));
          logoutBtn.setForeground(Color.white);
          
          logoutBtn.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub
                  moveToLogin();
  
              }
          });
          
          return logoutBtn;		
      }
  
      private void moveToLogin() {
           dashboardFrame.dispose();
           loginFrame.setVisible(true);
      }
   

Here we create a JPanel and its Action UI Buttons.

    
    JPanel actionPanel = new JPanel();
	    actionPanel.setLayout(null);
	    actionPanel.setBounds(panelWidth*5/100,panelHeight*27/100, panelWidth*90/100, panelHeight*35/100);
	    actionPanel.setBorder(Utils.getTitledBorder(16, "Action"));
	    panel.add(actionPanel);
	    
	    
	    actionPanel.add(addFlightBtn(panelWidth, panelHeight));
	    actionPanel.add(bookFlightBtn(panelWidth, panelHeight));
	    actionPanel.add(bookedFlightBtn(panelWidth, panelHeight));
	    actionPanel.add(addPassengerBtn(panelWidth, panelHeight));

        
	    // set visible window
	 	dashboardFrame.setVisible(true);

    

Here we define "addFlightBtn","bookFlightBtn","bookedFlightBtn", "addPassengerBtn" buttons and their click functionality.

    
    private JButton addFlightBtn(int width, int height) {
		  
          JButton addFlightBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
          addFlightBtn.setContentAreaFilled(false);
          addFlightBtn.setBorder(null);
          addFlightBtn.setBounds(width*10/100,(int) height*6/100, height*22/100, height*26/100); 
          addFlightBtn.setForeground(Color.black);
          addFlightBtn.setLayout(null);
          addFlightBtn.setOpaque(false);
          addFlightBtn.setContentAreaFilled(false);
          
          JLabel text = new JLabel("Add Flight");
          text.setHorizontalAlignment(JLabel.CENTER);
          text.setVerticalAlignment(JLabel.CENTER);
          text.setBackground(Color.decode("#80c2b2"));
          text.setForeground(Color.white);
          text.setFont(new java.awt.Font("Serif",0, 12));
          text.setBounds(0,height*18/100, height*22/100, height*5/100);
          addFlightBtn.add(text);
          
          
          ImageIcon backround_img1 = new ImageIcon("images/airplane.png");
          Image img1 = backround_img1.getImage();
          Image temp_img1 = img1.getScaledInstance(height*15/100, height*15/100, Image.SCALE_SMOOTH);
          backround_img1 = new ImageIcon(temp_img1);
          JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
          background1.setBounds((int) (height*3.8f/100),height*3/100, height*15/100, height*15/100);
          addFlightBtn.add(background1);
          
          
          
          addFlightBtn.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub
                  new AddFlight(dashboardFrame);
  
              }
          });
          
          return addFlightBtn;		
      }
      
      
      private JButton bookFlightBtn(int width, int height) {
            
          JButton bookFlightBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
          bookFlightBtn.setContentAreaFilled(false);
          bookFlightBtn.setBorder(null);
          bookFlightBtn.setBounds(width*30/100,(int) height*6/100, height*22/100, height*26/100); 
          bookFlightBtn.setForeground(Color.black);
          bookFlightBtn.setLayout(null);
          bookFlightBtn.setOpaque(false);
          bookFlightBtn.setContentAreaFilled(false);
          
          JLabel text = new JLabel("Book Flight");
          text.setHorizontalAlignment(JLabel.CENTER);
          text.setVerticalAlignment(JLabel.CENTER);
          text.setBackground(Color.decode("#80c2b2"));
          text.setForeground(Color.white);
          text.setFont(new java.awt.Font("Serif",0, 12));
          text.setBounds(0,height*18/100, height*22/100, height*5/100);
          bookFlightBtn.add(text);
          
          
          ImageIcon backround_img1 = new ImageIcon("images/booked_f.png");
          Image img1 = backround_img1.getImage();
          Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
          backround_img1 = new ImageIcon(temp_img1);
          JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
          background1.setBounds((int) (height*5f/100),height*5/100, height*12/100, height*12/100);
          bookFlightBtn.add(background1);
          
          
          
          bookFlightBtn.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub
                  
                  new FlightBooking(dashboardFrame);
  
              }
          });
          
          return bookFlightBtn;		
      }
  
      
      private JButton bookedFlightBtn(int width, int height) {
            
          JButton bookedFlightBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
          bookedFlightBtn.setContentAreaFilled(false);
          bookedFlightBtn.setBorder(null);
          bookedFlightBtn.setBounds(width*50/100,(int) height*6/100, height*22/100, height*26/100); 
          bookedFlightBtn.setForeground(Color.black);
          bookedFlightBtn.setLayout(null);
          bookedFlightBtn.setOpaque(false);
          bookedFlightBtn.setContentAreaFilled(false);
          
          JLabel text = new JLabel("Booked Flight");
          text.setHorizontalAlignment(JLabel.CENTER);
          text.setVerticalAlignment(JLabel.CENTER);
          text.setBackground(Color.decode("#80c2b2"));
          text.setForeground(Color.white);
          text.setFont(new java.awt.Font("Serif",0, 12));
          text.setBounds(0,height*18/100, height*22/100, height*5/100);
          bookedFlightBtn.add(text);
          
          
          ImageIcon backround_img1 = new ImageIcon("images/booked_f.png");
          Image img1 = backround_img1.getImage();
          Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
          backround_img1 = new ImageIcon(temp_img1);
          JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
          background1.setBounds((int) (height*5/100),height*5/100, height*12/100, height*12/100);
          bookedFlightBtn.add(background1);
          
          
          
          bookedFlightBtn.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub
              
                  new BookedFlight(dashboardFrame);
              }
          });
          
          return bookedFlightBtn;		
      }
   
      private JButton addPassengerBtn(int width, int height) {
            
          JButton addPassengerBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
          addPassengerBtn.setContentAreaFilled(false);
          addPassengerBtn.setBorder(null);
          addPassengerBtn.setBounds(width*70/100,(int) height*6/100, height*22/100, height*26/100); 
          addPassengerBtn.setForeground(Color.black);
          addPassengerBtn.setLayout(null);
          addPassengerBtn.setOpaque(false);
          addPassengerBtn.setContentAreaFilled(false);
          
          JLabel text = new JLabel("Add Passenger");
          text.setHorizontalAlignment(JLabel.CENTER);
          text.setVerticalAlignment(JLabel.CENTER);
          text.setBackground(Color.decode("#80c2b2"));
          text.setForeground(Color.white);
          text.setFont(new java.awt.Font("Serif",0, 12));
          text.setBounds(0,height*18/100, height*22/100, height*5/100);
          addPassengerBtn.add(text);
          
          
          ImageIcon backround_img1 = new ImageIcon("images/add_student.png");
          Image img1 = backround_img1.getImage();
          Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
          backround_img1 = new ImageIcon(temp_img1);
          JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
          background1.setBounds((int) (height*5/100),height*5/100, height*12/100, height*12/100);
          addPassengerBtn.add(background1);
          
          
          
          addPassengerBtn.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub
                  new AddPassenger(dashboardFrame);
  
              }
          });
          
          return addPassengerBtn;		
      }
  
  
    

Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 2021 by Programmer Mitra. All Rights Reserved.