Solved

Applet Events

Posted on 1999-01-25
4
176 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java 8 lambda expresssions exception handling 3 88
Weekend adv creator 3 36
print map entry 34 67
Problem to Alipay 10 18
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now