My issue is, that i try replacing panels, to move from screen to screen. It worked so far with replacing one panel( Panel A for panel B), but now i've added a new panel (C) i want it to go from panel B to C. However, what happens is that goes from panel A straight to C.
Here is the code:
Expand|Select|Wrap|Line Numbers
- package terminal2;
- import javax.swing.*;
- import javax.imageio.*;
- import java.awt.image.*;
- import java.io.*;
- import java.awt.event.*;
- import java.awt.*;
- class terminal implements ActionListener
- {
- private JFrame mainF=new JFrame("Welcome to Cairo Int Airport TERMINAL 2");
- private JPanel welcome=new JPanel();
- private JPanel ticket=new JPanel();
- private JPanel seats=new JPanel();
- private JPanel clkPanel=new JPanel();
- //Panels for headers.
- JPanel head=new JPanel();
- JPanel Header=new JPanel();
- private Clock clk=new Clock();
- //Layouts
- FlowLayout flow=new FlowLayout();
- GridLayout g=new GridLayout(3,1);
- BorderLayout main=new BorderLayout();
- public terminal()
- {
- //Fonts
- Font header=new Font("Arial",Font.BOLD,32);
- Font textF=new Font("Arial",Font.ITALIC,18);
- Font labels=new Font("Arial",Font.BOLD,14);
- //Layouts
- flow.setAlignment(FlowLayout.CENTER);
- clkPanel.setLayout(flow);
- clkPanel.add(clk);
- clkPanel.setBackground(Color.RED);
- //Frame
- mainF.setVisible(true);
- mainF.setSize(1200,800);
- mainF.setLayout(new FlowLayout());
- mainF.setBackground(Color.ORANGE);
- mainF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Dimensions
- Dimension field=new Dimension(75,25);
- Dimension but=new Dimension(100,50);
- ////----------------WELCOME PAGE-----------------------------
- //Welcome Panel
- welcome.setLayout(main);
- welcome.setBackground(Color.orange);
- // Header
- JPanel nort=new JPanel();
- nort.setLayout(flow);
- nort.setBackground(Color.red);
- JPanel north=new JPanel();
- JPanel box1=new JPanel();
- JPanel box2=new JPanel();
- north.setLayout(g);
- box1.setLayout(flow);
- box2.setLayout(flow);
- box1.setBackground(Color.red);
- box2.setBackground(Color.red);
- JLabel wel=new JLabel("Welcome to Cairo Int Airport");
- JLabel wel2=new JLabel("TERMINAL 2");
- wel.setFont(header);
- wel2.setFont(header);
- box1.add(wel);
- box2.add(wel2);
- north.add(box1);
- north.add(box2);
- north.add(clkPanel);
- nort.add(north);
- welcome.add(nort,BorderLayout.NORTH);
- //Center
- JPanel centerW=new JPanel();
- JPanel text=new JPanel();
- JPanel button=new JPanel();
- centerW.setLayout(g);
- text.setLayout(flow);
- button.setLayout(flow);
- centerW.setBackground(Color.orange);
- text.setBackground(Color.orange);
- button.setBackground(Color.orange);
- JLabel start=new JLabel("Press button to start Check-in");
- start.setFont(textF);
- JButton strt=new JButton("start");
- strt.setSize(200, 50);
- strt.setPreferredSize(but);
- strt.addActionListener(this);
- strt.setBackground(Color.WHITE);
- text.add(start);
- button.add(strt);
- centerW.add(text);
- centerW.add(button);
- welcome.add(centerW,BorderLayout.CENTER);
- //Image left and right panel.
- JPanel left=new JPanel();
- JPanel right=new JPanel();
- left.setBackground(Color.black);
- right.setBackground(Color.black);
- BufferedImage lPhoto = null;
- try {
- lPhoto= ImageIO.read(new File("left.jpg"));
- } catch (IOException e) { }
- JLabel l=new JLabel(new ImageIcon(lPhoto));
- BufferedImage rPhoto= null;
- try {
- rPhoto = ImageIO.read(new File("right.jpg"));
- } catch (IOException e) { }
- JLabel r=new JLabel(new ImageIcon(rPhoto));
- left.add(l);
- right.add(r,new FlowLayout(FlowLayout.LEFT));
- welcome.add(left,BorderLayout.WEST);
- welcome.add(right,BorderLayout.EAST);
- mainF.add(welcome);
- mainF.pack();
- //----------------------TICKET PAGE-------------------------------
- //Ticket Panel
- ticket.setLayout(main);
- //Head
- head.setLayout(g);
- head.setBackground(Color.red);
- JPanel hText=new JPanel();
- hText.setLayout(flow);
- JLabel ticketH=new JLabel("Please enter your ticket or Booking number");
- ticketH.setFont(header);
- hText.add(ticketH);
- head.add(hText);
- ticket.add(head,BorderLayout.NORTH);
- //Center
- JPanel centerT=new JPanel();
- JPanel grid=new JPanel();
- JPanel bookingP=new JPanel();
- centerT.setPreferredSize(new Dimension(600,700));
- centerT.setLayout(flow);
- grid.setLayout(new GridLayout(8,2));
- bookingP.setLayout(new FlowLayout());
- centerT.setBackground(Color.ORANGE);
- grid.setBackground(Color.ORANGE);
- bookingP.setBackground(Color.WHITE);
- //Booking Panel
- JLabel booking=new JLabel("Booking ID");
- JTextField bookingF=new JTextField();
- JButton checkBook=new JButton("Check");
- checkBook.setPreferredSize(but);
- checkBook.addActionListener(this);
- bookingF.setPreferredSize(field);
- booking.setLabelFor(bookingF);
- bookingP.add(booking);
- bookingP.add(bookingF);
- grid.add(bookingP);
- grid.add(checkBook);
- JLabel labelName=new JLabel("Passenger Name:");
- JLabel fieldName=new JLabel();
- labelName.setFont(labels);
- fieldName.setPreferredSize(field);
- labelName.setLabelFor(fieldName);
- grid.add(labelName);
- grid.add(fieldName);
- JLabel labelFlight=new JLabel("Flight No:");
- labelFlight.setFont(labels);
- JLabel fieldFlight=new JLabel();
- fieldFlight.setPreferredSize(field);
- labelFlight.setLabelFor(fieldFlight);
- grid.add(labelFlight);
- grid.add(fieldFlight);
- JLabel labelDest=new JLabel("Destination:");
- labelDest.setFont(labels);
- JLabel fieldDest=new JLabel();
- fieldDest.setPreferredSize(field);
- labelDest.setLabelFor(fieldDest);
- grid.add(labelDest);
- grid.add(fieldDest);
- JLabel labelTime=new JLabel("Time (HH:MM:SS):");
- labelTime.setFont(labels);
- JLabel fieldTime=new JLabel();
- fieldTime.setPreferredSize(field);
- labelTime.setLabelFor(fieldTime);
- grid.add(labelTime);
- grid.add(fieldTime);
- JLabel labelPassenger=new JLabel("Passengers:");
- labelPassenger.setFont(labels);
- JTextArea areaPassenger=new JTextArea();
- areaPassenger.setPreferredSize(new Dimension(200,100));
- labelPassenger.setLabelFor(areaPassenger);
- grid.add(labelPassenger);
- grid.add(areaPassenger);
- JLabel labelCorrect=new JLabel("Is this information correct?");
- labelCorrect.setFont(labels);
- JPanel choice=new JPanel();
- choice.setLayout(flow);
- JButton yes=new JButton("Yes");
- yes.addActionListener(this);
- yes.setPreferredSize(but);
- JButton no=new JButton("No");
- no.setPreferredSize(but);
- choice.setBackground(Color.orange);
- choice.add(yes);
- choice.add(no);
- grid.add(labelCorrect);
- grid.add(choice);
- centerT.add(grid);
- ticket.add(centerT,BorderLayout.CENTER);
- mainF.pack();
- //=----------------Seating------------------------------------
- seats.setLayout(main);
- //Header
- JPanel headP=new JPanel();
- headP.setLayout(flow);
- headP.setBackground(Color.red);
- Header.setLayout(g);
- Header.setBackground(Color.red);
- JLabel seatH=new JLabel("Please select your seats");
- seatH.setFont(header);
- Header.add(seatH);
- headP.add(Header);
- seats.add(headP,BorderLayout.NORTH);
- mainF.pack();
- //-----------------Baggage------------------------------------
- //***********OVERWEIGHT****************************
- //----------------Summary--------------------------------------
- //******************Boarding Pass***********************
- }
- public void actionPerformed(ActionEvent e) {
- //WELCOME SELECTIONS
- if(e.getActionCommand().equals("start"))
- {
- mainF.remove(welcome);
- head.add(clkPanel);
- mainF.add(ticket);
- mainF.validate();
- mainF.repaint();
- //TICKETS SELECTIONS
- }else if(e.getActionCommand().equals("Check"))
- {
- }else if(e.getActionCommand().equals("yes"));
- {
- mainF.remove(ticket);
- mainF.add(seats);
- Header.add(clkPanel);
- mainF.validate();
- mainF.repaint();
- }
- }
- };
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- terminal wel=new terminal();
- }
- }