Solved

Applet Events

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:

708 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