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 8 of 8

Thread: menu screen for a program, anyone know a way of writing the code more elagantly.

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    19
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default menu screen for a program, anyone know a way of writing the code more elagantly.

    I'm attempting to write a menu screen for a program, and am a complete noob at swing. I am using JLabel's to display the graphics that I have chosen for the buttons. At the moment the code for changing the menu screen is just under the MouseClicked method for the JLabel. So for one JLabel I will have;

    public void MouseClicked(){
    remove(all items in this screen);
    add(all items for the next screen, dependant on which button was clicked);
    }

    This does work, but is extremely messy, and I am certain that their is a better way of doing it. Does anyone have any ideas? On how to neaten it up.
    Last edited by handuel; November 23rd, 2011 at 02:15 PM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    Why don't you create multiple frames, each having it's own components and simply on some event hide the previous frame and show the one, event is triggered for?

  3. The Following User Says Thank You to Mr.777 For This Useful Post:

    handuel (November 26th, 2011)

  4. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    19
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    lol, I don't really know how to do that.
    Although if I work it out it is a good idea.

  5. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    19
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    Thanks, I worked out how to to that, after a bit... [embarrassed] thnx.

  6. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    19
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    Still got a problem :O
    If a new frame opens, windows plays the "window openy animation." when the window kind of zooms up to the position it is meant to be in. Is there any way of stopping this.

  7. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    Quote Originally Posted by handuel View Post
    Still got a problem :O
    If a new frame opens, windows plays the "window openy animation." when the window kind of zooms up to the position it is meant to be in. Is there any way of stopping this.
    What do you mean?

  8. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    19
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    the answer you gave requires opening a new frame/window when a button is clicked. On windows, when a window is opened, the image of the frame zooms outward from the centre of the screen, before actually being able to be used. This, when it happens in my program, gives the impression that a new frame/window has been opened, instead of the contents of the current frame changing.

  9. #8
    Junior Member
    Join Date
    Nov 2011
    Posts
    19
    My Mood
    Inspired
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: menu screen for a program, anyone know a way of writing the code more elagantly.

    I think I've solved it, I'm messing around with card layouts and they seem to work.
    Thankyou mr777 for all your help.
    Once I've finished I will post the code, so people can tell me if it's an improvement.

Similar Threads

  1. Replies: 9
    Last Post: December 31st, 2011, 01:22 AM
  2. Is it possible to use card layout for menu and menu items?
    By jai2rul in forum AWT / Java Swing
    Replies: 0
    Last Post: April 11th, 2011, 08:19 AM
  3. JFrame Menu Screen(For my game)?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 2
    Last Post: March 8th, 2010, 04:07 AM
  4. Help - Return to menu screen
    By throzen in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 29th, 2009, 01:44 PM
  5. I need help writing this program
    By kev2000 in forum Algorithms & Recursion
    Replies: 5
    Last Post: June 4th, 2009, 03:14 AM

Tags for this Thread