Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Creating subsequent frames in java with Jframe

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Creating subsequent frames in java with Jframe

    Hi,

    I am making a small application. I want the first frame to be a sort of username / password login. When the user presses ok, and if the username and password are correct, then the next screen will appear (and if username and password are incorrect, an error dialog box appears).

    I am using NetBeans. I have created 2 frames, FrameOne and FrameTwo. In the main class, I have constructed the two frames and set them as visible, but the problem is that they pop up simultaneously. I want FrameTwo to appear only after FrameOne is closed.

    Any isead on how to do this?

    Thanks

    ublic class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
     
            FrameOne front = new FrameOne();
            front.setVisible(true);
     
            FrameTwo frametwo = new FrameTwo();
            frametwo.setVisible(true);
     
     
     
        }
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Creating subsequent frames in java with Jframe

    Sounds like a job for a dialog: How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    But you're setting both JFrames to be visible, so that's exactly what's going to happen. If you really want to use JFrames (use a dialog), you'll have to add a Listener to the first JFrame that pops up the other one upon closing. But use a dialog.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Creating subsequent frames in java with Jframe

    KevinWorkman,

    Thanks for your reply. this will surely be helpful, but what I am after is something like when you are installing an application, and you get NEXT and then another screen pops up (killing the first one).

    I think the logic is the same as a dialog, but what i have to do is to call another frame rather a dialog. This is becasue i have some methods where the user would have to click on some buttons (i.e. in the second frame, the user will have to add or subtract a balance from an account.

    Do you agree with my logic?

    thanks

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Creating subsequent frames in java with Jframe

    That's fine. I'm still pretty sure you can do this with dialogs. But you could also just add the correct Listener- such as an ActionListener on a JButton, that sets the visibility of one JFrame to false and another to true.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Creating a Compiler in Java
    By Superstar288 in forum Java Theory & Questions
    Replies: 20
    Last Post: February 22nd, 2013, 09:05 AM
  2. creating GUI using java, need help?
    By koko20 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 5th, 2011, 02:51 PM
  3. Switching between frames from a seperate class
    By kurt-hardy in forum AWT / Java Swing
    Replies: 4
    Last Post: February 14th, 2011, 04:19 AM
  4. Java Gif image problem in JFrame
    By Zachary Wins in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 23rd, 2010, 08:51 PM
  5. GIF frames
    By vsector in forum AWT / Java Swing
    Replies: 0
    Last Post: April 15th, 2010, 05:25 PM