Results 1 to 8 of 8
  1. #1
    Bonia is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default can't close previous frame to see well new frame java

    I have a problem with frames. I think my problem is logic one. I open menu frame and then when I click add passenger the frame doesn't open wel. I still can see previous frame. I used ideas posted on this forum to change setVisisble to (false) and I thought I will see correctly other frame but it didn't work well. Could you please give me some advice. Thank you

    public class DriverProgram
    {
    public static void main (String [ ] argument)
    {
    Flight sw101 = new Flight();
    sw101.setVisible(true);
    }
    }

    import corejava.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class Flight extends JFrame
    {
    SeatingChart sc = new SeatingChart();
    WaitingList wl = new WaitingList();
    private String buttons[] = new String[5];
    private final Font MENU_FONT = new Font("Serif", Font.BOLD, 20);
    JButton b;
    ActionListener listener1 = new MenuClickListener();
    private JTextField input =null;
    private JTextField firstName;
    private JTextField middleName;
    private JTextField lastName;
    private final Font NEW_FONT = new Font("Serif", Font.BOLD + Font.ITALIC, 20);

    public Flight()
    {
    menu();
    }

    void menu( )
    {
    uiFrameMenu();
    addPanelMenu();
    }

    void uiFrameMenu()
    {
    setTitle( "MENU" );
    setSize( 400, 400 );
    setLocationRelativeTo( null );
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }

    void addPanelMenu()
    {
    setLayout( new BorderLayout() );
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout (5,1));

    buttons[0] = "Add Passenger";
    buttons[1] = "Remove Passenger";
    buttons[2] = "Seating Chart";
    buttons[3] = "Waiting List";
    buttons[4] = "Exit";


    for( int i = 0; i < buttons.length ; i++ )
    {
    b = new JButton( buttons[i]);
    b.setText( buttons[i] );
    b.setForeground(Color.BLACK);
    b.setFont(MENU_FONT);
    b.addActionListener(listener1);
    panel.add(b);
    }

    getContentPane();
    panel.setBackground(Color.MAGENTA);
    add(panel,"Center");
    }

    class MenuClickListener implements ActionListener
    {
    MenuClickListener() { }

    @Override
    public void actionPerformed( ActionEvent event )
    {
    if ( event.getActionCommand().equals(buttons[0]))
    {
    addPassenger();
    }
    else if ( event.getActionCommand().equals(buttons[1]))
    {

    }
    setVisible(true);
    }
    }



    void addPassenger( )
    {
    this.setEnabled(false);
    uiFrameData();
    setLayout( new BorderLayout() );
    JPanel panel1 = new JPanel();
    panel1.setLayout( new GridLayout(3, 2) );
    JPanel panel2 = new JPanel();
    panel2.setLayout( new GridLayout(3, 1) );
    JLabel l1 = new JLabel("First Name");
    JLabel l2 = new JLabel("Middle Name");
    JLabel l3 = new JLabel("Last Name");
    firstName = new JTextField();
    middleName = new JTextField();
    lastName = new JTextField();
    panel1.add(l1);
    panel1.add(firstName);
    panel1.add(l2);
    panel1.add(middleName);
    panel1.add(l3);
    panel1.add(lastName);
    add(panel1);
    }

    void uiFrameData()
    {
    setTitle( "FIRST, MIDDLE AND LAST NAME" );
    setSize( 400, 400 );
    //setLocationRelativeTo( null );
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: can't close previous frame to see well new frame java

    Please do not cross-post questions in multiple forums. This will frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. For this reason, many volunteers here and at the other sites refuse to help repeat offenders.

    So in this light, please post links to all cross-posts of this question.

  3. #3
    Bonia is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: can't close previous frame to see well new frame java


  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: can't close previous frame to see well new frame java

    Thanks. Again, CardLayout is what you want to use for this.

  5. #5
    Bonia is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: can't close previous frame to see well new frame java

    I have never used CardLayout and the code which you see is the one which I wrote so far using swings. Why I can not create few frames one after another. What's wrong in it?

    I was reading in t he internet that is possible to do it.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: can't close previous frame to see well new frame java

    Quote Originally Posted by Bonia View Post
    I have never used CardLayout
    And now is probably the perfect time to look at the tutorial and learn how!


    and the code which you see is the one which I wrote so far using swings.
    (that's "Swing" actually, but I digress).


    Why I can not create few frames one after another. What's wrong in it?
    um... well where do you have code that actually creates a new JFrame? Answer -- you don't. But regardless, no user is going to want to see JFrames flinging in and out of view. Trust me, a CardLayout would work *great* in this situation.

  7. #7
    Bonia is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: can't close previous frame to see well new frame java

    Thank you for all advices. It's done.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: can't close previous frame to see well new frame java

    You're welcome and congratulations!

Similar Threads

  1. Close a frame from another class
    By aborgeld in forum New To Java
    Replies: 11
    Last Post: 03-27-2011, 08:22 PM
  2. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 10:40 AM
  3. How do I close a frame with a button?
    By Psyclone in forum AWT / Swing
    Replies: 7
    Last Post: 02-19-2010, 10:43 PM
  4. close a frame..
    By tajinvillage in forum New To Java
    Replies: 5
    Last Post: 04-27-2008, 10:22 PM
  5. Frame close operation
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-21-2007, 08:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •