Solved

Applet Events

Posted on 1999-01-25
4
178 Views
Last Modified: 2010-05-18
I need to change the panel in BorderLayout.CENTER when the next button in BorderLayout.SOUTH is pressed.  Is there a way to update one panel in a layout using the events?  How do I do it?  

Thanks
0
Comment
Question by:willpd
  • 2
4 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 1234627
there is no problem updating whatever you wand based on some user actions.

please be more specific.
0
 

Author Comment

by:willpd
ID: 1234628
When the action is captured, how do I change the panel?  

For example:

public void actionPerformed(ActionEvent e)
{
    String Label = (String) e.getActionCommand();
   
    if (Label.equals("Next"))
    {

      ***HERE***
    }


Can you give me a code sample of how I would change the panel in the CENTER at that point?


Thanks
0
 
LVL 3

Accepted Solution

by:
sailwind earned 100 total points
ID: 1234629
The implementation would more or less depend on what you have
in the center. The easiest thing to do is to remove the original
panel and add the new one. If you have an image in the middle,
then you might want to just switch the image without using a
new panel. At any rate, let's assume you have something like:

JPanel centerPane = new JPanel();
JPanel southPane = new Japenl();
JPanel replacementPane = new JPanel();

JPanel mainDisplay = new JPanel();
mainDisplay.setLayout(new BorderLayout());
mainDisplay.add(centerPane, "Center");
mainDisplay.add(southPane, "South");

Then, in your actionPerformed, you can just do:

public void actionPerformed(ActionEvent e)
{
    String Label = (String) e.getActionCommand();
           
    if (Label.equals("Next"))
    {
         // do the replacement
         mainDisplay.remove(centerPane);
         mainDisplay.add(replacementPane, "Center");

         // repaint itself and all subcomponents  
         mainDisplay.repaintAll();
       
           }
0
 

Author Comment

by:willpd
ID: 1234630
Perfect! That's exactly what I needed to know.  Thanks a lot!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 60
Better way to make a string with template variables in java 3 34
Why doesn't this text field show up on my Applet frame? 2 28
dao vs facade design patterns 2 38
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

726 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