Results 1 to 8 of 8
  1. #1
    Lowell is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Creating Interface that can switch

    Hi,
    What method /ways should I use to allow GUIs to switch from time to time when a user clicked something. Example: Login interface > Main menu > Game. I try card layout but it seems not working.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Creating Interface that can switch

    CardLayout seems a natural fit. Possibly if "it seems not working" that might have something to do with your code.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Creating Interface that can switch

    CardLayout seems a natural fit. Possibly if "it seems not working" that might have something to do with your code.

    [Edit] And welcome to the forums!

    I realise my answer was, maybe, a bit abrupt ;) Do post some code showing how you are attempting to use CardLayout. It doesn't have to be all your program logic (in fact, it shouldn't be) - but enough to show the problems you are having with it. Ie what compiler messages you get if it doesn't compile, or what it does or fails to do at runtime that isn't what you intend or want.

  4. #4
    Lowell is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Creating Interface that can switch

    i used netbean......I sees lots of tutorial on the internet but all seems so out of date. But if i coded it manually, it just work fine.

  5. #5
    Lowell is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Creating Interface that can switch

    Yay, thank you. Finally it works. I followed here Hello Blog: Using CardLayout in Netbeans
    By the way, i need to know something about this code

    CardLayout z = (CardLayout)mainPanel.getLayout();
    z.next(mainPanel);
    (CardLayout) <-----Means ?
    then getLayout()<------Means?

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Creating Interface that can switch

    getLayout() is a panel method that returns a layout. In particular it returns the panel's layout.

    But the code wants to assign what it returns to a CardLayout variable. The Java compiler gets upset with this. Basically it says "getLayout() returns a Layout but you want to assign to a specific CardLayout subclass. That could be dangerous if the layout turns out not to be a CardLayout!"

    The (CardLayout) thing is called a "cast". It tells the compiler "don't worry, at runtime the Layout that is returned will really be a CardLayout". The cast is required for the code to compile.

  7. #7
    Lowell is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Creating Interface that can switch

    Thanks! All understood (:

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

Similar Threads

  1. need help creating my own iterator interface
    By liluma in forum New To Java
    Replies: 2
    Last Post: 10-10-2011, 07:31 PM
  2. creating an interface
    By Billaguana in forum New To Java
    Replies: 3
    Last Post: 01-16-2011, 10:05 PM
  3. Creating API Interface
    By ashanti in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 03:08 AM
  4. Creating a Thread using the Runnable interface
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:31 PM

Posting Permissions

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