Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Applet Events

Posted on 1999-01-25
4
Medium Priority
?
182 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 400 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
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:
Suggested Courses

596 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