473,421 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Panel Swapping! Help needed!!!

Hi all, i am working on an assignment where i have to design an automatic check in system for an airport. I am using the swing library, as well as using actionlisteners.

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
  1. package terminal2;
  2.  
  3. import javax.swing.*;
  4. import javax.imageio.*;
  5. import java.awt.image.*;
  6. import java.io.*;
  7. import java.awt.event.*;
  8. import java.awt.*;
  9.  
  10.  
  11. class terminal implements ActionListener
  12. {
  13.     private JFrame mainF=new JFrame("Welcome to Cairo Int Airport TERMINAL 2");
  14.     private JPanel welcome=new JPanel();
  15.     private JPanel ticket=new JPanel();
  16.     private JPanel seats=new JPanel();
  17.     private JPanel clkPanel=new JPanel();
  18.  
  19.     //Panels for headers.
  20.     JPanel head=new JPanel();
  21.     JPanel Header=new JPanel();
  22.  
  23.     private Clock clk=new Clock();
  24.  
  25.  
  26.     //Layouts
  27.  
  28.     FlowLayout flow=new FlowLayout();
  29.     GridLayout g=new GridLayout(3,1);
  30.     BorderLayout main=new BorderLayout();
  31.  
  32.  
  33.  
  34.     public terminal()
  35.     {
  36.  
  37.          //Fonts
  38.         Font header=new Font("Arial",Font.BOLD,32);
  39.         Font textF=new Font("Arial",Font.ITALIC,18);
  40.         Font labels=new Font("Arial",Font.BOLD,14);
  41.  
  42.         //Layouts
  43.  
  44.         flow.setAlignment(FlowLayout.CENTER);
  45.  
  46.  
  47.         clkPanel.setLayout(flow);
  48.         clkPanel.add(clk);
  49.         clkPanel.setBackground(Color.RED);
  50.  
  51.  
  52.         //Frame
  53.         mainF.setVisible(true);
  54.         mainF.setSize(1200,800);
  55.         mainF.setLayout(new FlowLayout());
  56.         mainF.setBackground(Color.ORANGE);
  57.         mainF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58.  
  59.         //Dimensions
  60.  
  61.         Dimension field=new Dimension(75,25);
  62.         Dimension but=new Dimension(100,50);
  63.  
  64.  
  65.         ////----------------WELCOME PAGE-----------------------------
  66.  
  67.             //Welcome Panel
  68.  
  69.             welcome.setLayout(main);
  70.             welcome.setBackground(Color.orange);
  71.  
  72.  
  73.  
  74.  
  75.             // Header
  76.  
  77.             JPanel nort=new JPanel();
  78.             nort.setLayout(flow);
  79.             nort.setBackground(Color.red);
  80.             JPanel north=new JPanel();
  81.  
  82.             JPanel box1=new JPanel();
  83.             JPanel box2=new JPanel();
  84.  
  85.  
  86.             north.setLayout(g);
  87.             box1.setLayout(flow);
  88.             box2.setLayout(flow);
  89.             box1.setBackground(Color.red);
  90.             box2.setBackground(Color.red);
  91.  
  92.             JLabel wel=new JLabel("Welcome to Cairo Int Airport");
  93.             JLabel wel2=new JLabel("TERMINAL 2");
  94.  
  95.             wel.setFont(header);
  96.             wel2.setFont(header);
  97.  
  98.             box1.add(wel);
  99.             box2.add(wel2);
  100.             north.add(box1);
  101.             north.add(box2);
  102.             north.add(clkPanel);
  103.             nort.add(north);
  104.  
  105.             welcome.add(nort,BorderLayout.NORTH);
  106.  
  107.             //Center
  108.  
  109.             JPanel centerW=new JPanel();
  110.             JPanel text=new JPanel();
  111.             JPanel button=new JPanel();
  112.  
  113.             centerW.setLayout(g);
  114.             text.setLayout(flow);
  115.             button.setLayout(flow);
  116.             centerW.setBackground(Color.orange);
  117.             text.setBackground(Color.orange);
  118.             button.setBackground(Color.orange);
  119.  
  120.             JLabel start=new JLabel("Press button to start Check-in");
  121.             start.setFont(textF);
  122.             JButton strt=new JButton("start");
  123.             strt.setSize(200, 50);
  124.  
  125.             strt.setPreferredSize(but);
  126.             strt.addActionListener(this);
  127.             strt.setBackground(Color.WHITE);
  128.  
  129.             text.add(start);
  130.             button.add(strt);
  131.             centerW.add(text);
  132.             centerW.add(button);
  133.  
  134.             welcome.add(centerW,BorderLayout.CENTER);
  135.  
  136.             //Image left and right panel.
  137.  
  138.            JPanel left=new JPanel();
  139.            JPanel right=new JPanel();
  140.            left.setBackground(Color.black);
  141.            right.setBackground(Color.black);
  142.  
  143.            BufferedImage lPhoto = null;
  144.             try {
  145.                lPhoto= ImageIO.read(new File("left.jpg"));
  146.             } catch (IOException e) {            }
  147.  
  148.             JLabel l=new JLabel(new ImageIcon(lPhoto));
  149.  
  150.             BufferedImage rPhoto= null;
  151.             try {
  152.                rPhoto = ImageIO.read(new File("right.jpg"));
  153.             } catch (IOException e) {            }
  154.  
  155.             JLabel r=new JLabel(new ImageIcon(rPhoto));
  156.  
  157.             left.add(l);
  158.             right.add(r,new FlowLayout(FlowLayout.LEFT));
  159.  
  160.             welcome.add(left,BorderLayout.WEST);
  161.             welcome.add(right,BorderLayout.EAST);
  162.  
  163.  
  164.             mainF.add(welcome);
  165.             mainF.pack();
  166.  
  167.     //----------------------TICKET PAGE-------------------------------
  168.  
  169.             //Ticket Panel
  170.  
  171.             ticket.setLayout(main);
  172.  
  173.             //Head
  174.  
  175.  
  176.             head.setLayout(g);
  177.             head.setBackground(Color.red);
  178.  
  179.            JPanel hText=new JPanel();
  180.            hText.setLayout(flow);
  181.  
  182.             JLabel ticketH=new JLabel("Please enter your ticket or Booking number");
  183.            ticketH.setFont(header);
  184.            hText.add(ticketH);
  185.            head.add(hText);
  186.  
  187.            ticket.add(head,BorderLayout.NORTH);
  188.  
  189.            //Center
  190.  
  191.            JPanel centerT=new JPanel();
  192.            JPanel grid=new JPanel();
  193.            JPanel bookingP=new JPanel();
  194.  
  195.            centerT.setPreferredSize(new Dimension(600,700));
  196.  
  197.            centerT.setLayout(flow);
  198.            grid.setLayout(new GridLayout(8,2));
  199.            bookingP.setLayout(new FlowLayout());
  200.  
  201.            centerT.setBackground(Color.ORANGE);
  202.            grid.setBackground(Color.ORANGE);
  203.            bookingP.setBackground(Color.WHITE);           
  204.  
  205.                //Booking Panel
  206.                JLabel booking=new JLabel("Booking ID");
  207.                JTextField bookingF=new JTextField();
  208.                JButton checkBook=new JButton("Check");
  209.                checkBook.setPreferredSize(but);
  210.                checkBook.addActionListener(this);
  211.  
  212.                bookingF.setPreferredSize(field);
  213.                booking.setLabelFor(bookingF);
  214.                bookingP.add(booking);
  215.                bookingP.add(bookingF);
  216.  
  217.  
  218.            grid.add(bookingP);
  219.            grid.add(checkBook);
  220.  
  221.            JLabel labelName=new JLabel("Passenger Name:");
  222.            JLabel fieldName=new JLabel();
  223.            labelName.setFont(labels);
  224.            fieldName.setPreferredSize(field);
  225.            labelName.setLabelFor(fieldName);
  226.            grid.add(labelName);
  227.            grid.add(fieldName);
  228.  
  229.            JLabel labelFlight=new JLabel("Flight No:");
  230.            labelFlight.setFont(labels);
  231.            JLabel fieldFlight=new JLabel();
  232.            fieldFlight.setPreferredSize(field);
  233.            labelFlight.setLabelFor(fieldFlight);
  234.            grid.add(labelFlight);
  235.            grid.add(fieldFlight);
  236.  
  237.            JLabel labelDest=new JLabel("Destination:");
  238.            labelDest.setFont(labels);
  239.            JLabel fieldDest=new JLabel();
  240.            fieldDest.setPreferredSize(field);
  241.            labelDest.setLabelFor(fieldDest);
  242.            grid.add(labelDest);
  243.            grid.add(fieldDest);
  244.  
  245.            JLabel labelTime=new JLabel("Time (HH:MM:SS):");
  246.            labelTime.setFont(labels);
  247.            JLabel fieldTime=new JLabel();
  248.            fieldTime.setPreferredSize(field);
  249.            labelTime.setLabelFor(fieldTime);
  250.            grid.add(labelTime);
  251.            grid.add(fieldTime);
  252.  
  253.            JLabel labelPassenger=new JLabel("Passengers:");
  254.            labelPassenger.setFont(labels);
  255.            JTextArea areaPassenger=new JTextArea();
  256.            areaPassenger.setPreferredSize(new Dimension(200,100));
  257.            labelPassenger.setLabelFor(areaPassenger);
  258.            grid.add(labelPassenger);
  259.            grid.add(areaPassenger);
  260.  
  261.            JLabel labelCorrect=new JLabel("Is this information correct?");
  262.            labelCorrect.setFont(labels);
  263.                 JPanel choice=new JPanel();
  264.                 choice.setLayout(flow);
  265.                 JButton yes=new JButton("Yes");
  266.                 yes.addActionListener(this);
  267.                 yes.setPreferredSize(but);
  268.                 JButton no=new JButton("No");
  269.                 no.setPreferredSize(but);
  270.  
  271.                 choice.setBackground(Color.orange);
  272.                 choice.add(yes);
  273.                 choice.add(no);
  274.             grid.add(labelCorrect);
  275.             grid.add(choice);
  276.  
  277.  
  278.  
  279.  
  280.            centerT.add(grid);
  281.  
  282.            ticket.add(centerT,BorderLayout.CENTER);
  283.            mainF.pack();
  284.  
  285.  
  286.        //=----------------Seating------------------------------------
  287.  
  288.            seats.setLayout(main);
  289.  
  290.            //Header
  291.  
  292.            JPanel headP=new JPanel();
  293.            headP.setLayout(flow);
  294.            headP.setBackground(Color.red);
  295.            Header.setLayout(g);
  296.            Header.setBackground(Color.red);
  297.  
  298.            JLabel seatH=new JLabel("Please select your seats");
  299.            seatH.setFont(header);
  300.  
  301.            Header.add(seatH);
  302.  
  303.            headP.add(Header);
  304.            seats.add(headP,BorderLayout.NORTH);
  305.  
  306.  
  307.            mainF.pack();
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.        //-----------------Baggage------------------------------------
  317.  
  318.  
  319.  
  320.  
  321.            //***********OVERWEIGHT****************************
  322.  
  323.  
  324.  
  325.        //----------------Summary--------------------------------------
  326.  
  327.  
  328.  
  329.            //******************Boarding Pass***********************
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.     }
  343.  
  344.     public void actionPerformed(ActionEvent e) {
  345.  
  346.         //WELCOME SELECTIONS
  347.  
  348.         if(e.getActionCommand().equals("start"))
  349.         {
  350.             mainF.remove(welcome);
  351.             head.add(clkPanel);
  352.             mainF.add(ticket);
  353.  
  354.             mainF.validate();
  355.             mainF.repaint();
  356.  
  357.  
  358.         //TICKETS SELECTIONS
  359.  
  360.         }else if(e.getActionCommand().equals("Check"))
  361.         {
  362.  
  363.  
  364.         }else if(e.getActionCommand().equals("yes"));
  365.         {
  366.             mainF.remove(ticket);
  367.             mainF.add(seats);
  368.             Header.add(clkPanel);
  369.             mainF.validate();
  370.             mainF.repaint();
  371.  
  372.         }
  373.  
  374.  
  375.  
  376.     }
  377.  
  378.  
  379. };
  380.  
  381. public class Main {
  382.  
  383.     /**
  384.      * @param args the command line arguments
  385.      */
  386.     public static void main(String[] args) {
  387.  
  388.         terminal wel=new terminal();
  389.     }
  390.  
  391. }
Apr 30 '10 #1
0 1281

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: Douglas Alan | last post by:
While writing a generator, I was just thinking how Python needs a "yield_all" statement. With the help of Google, I found a pre-existing discussion on this from a while back in the Lightweight...
270
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these...
1
by: John | last post by:
I'm trying to use the DrawText() method to draw some very long string text on the Panel with AutoScroll enabled. However, for some unknown reasons, I could not trigger the ScrollBar to show up. ...
11
by: BoloBaby | last post by:
OK, check this out... I have a form with a panel control and button on it (outside the panel control). I have two event handlers - one handles the click event of the button on the form. The...
3
by: stotty | last post by:
Hello. I am developing an application that uses Panels to guide the user through a form they must fill out. Each Panel contains different controls, such as Text Boxes and Drop Down Lists. When...
3
by: splintercell | last post by:
well i got this code from java.sun.com and tried modiifying it in all the possible ways,but to no good.. stil its not workin..pleas help me out and try postin good workinw web cralwer if u have.....
9
by: she_prog | last post by:
Dear All, I need to save the content of a panel to a bitmap. The panel can have many child controls which also need to be saved. The problem would be solved if I could have the panel saved to a...
1
by: mbruyns | last post by:
i have been trying (and sometimes succeeding) to use the modalpopupextender to show various panels of controls on my asp pages. the strange problem that i keep on running into is that sometimes it...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.