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

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.

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.

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.

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.