Solved

Multiple JPanel in JApplet

Posted on 2007-11-21
2
1,150 Views
Last Modified: 2013-11-23
This should be a simple task, but I don't do that much with Java.

5 different JPanel classes which handle their own actions have been created.  For this conversation we will call them MyPanel1 ... MyPanel 5.  The first of these is a button/keypad menu.  All of this must run within a JApplet.  When the user selects one of the buttons a new class instance is created of the appropriate class and becomes the content for the JApplet.  When the user wishes to exit that JPanel they chose an exit option and it finalizes.  The JApplet should redisplay the original menu JPanel class (MyPanel1 for this discussion).

Need to see a code snippet for the switching back and forth.

0
Comment
Question by:yyyc186
2 Comments
 
LVL 92

Expert Comment

by:objects
ID: 20331805
a CardLayout can be used for easily switching between panels
0
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 250 total points
ID: 20331824
In my opinion, in this case it is the most appropriate to use CardLayout class, to realize that kind of panel switching.

You should have one main panel with 5 panels added to it using CardLayout. Initialy MyPanel1 instance will be visible. When user choose some button from MyPanel1, main panel will switch its content to appropriate panel. When user wants to return to MyPanel1, clicking the appropriate "exit" button will make MyPanel1 visible again.

Examples:
1.) http://www.science.uva.nl/ict/ossdocs/java/tutorial/ui/layout/card.html
2.) http://www.javareference.com/jrexamples/viewexample.jsp?id=28
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question