Solved

Applet Events

Posted on 1999-01-25
4
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

718 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