?
Solved

action performed?

Posted on 2004-10-12
18
Medium Priority
?
226 Views
Last Modified: 2010-03-31
Hi experts.

ok I have a dektop in the center of the content pane and a panel on the east. then I have a method that will arrange the internal frames in the desktop a certain way.  now the method is working but I had to create a button and have this method in actionperformed resulting from pressing the button. I would like to have the method called when any component (whatever it is) is added onto the panel..how do I do that?
0
Comment
Question by:Samooramad
[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
  • 6
  • 6
  • 6
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12290682
Add a ComponentListener
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12290685
You mean you want to call a certain function whenever a component is added to the panel?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12290702
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 37

Expert Comment

by:zzynx
ID: 12290707
Indeed, then a component listener could help.
But, aren't you adding the components yourself then?
Otherwise you could simply call your function after each add()
Or do I forget something?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12290719
0
 

Author Comment

by:Samooramad
ID: 12291488
>>But, aren't you adding the components yourself then

no not neccessarlly
0
 

Author Comment

by:Samooramad
ID: 12291518
which do I use ? component listener or container listener?
whats the difference?
0
 

Author Comment

by:Samooramad
ID: 12291532
CEHJ, you mean use container listener and componentAdded() ?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 600 total points
ID: 12291574
>>CEHJ, you mean use container listener and componentAdded() ?

Yes
0
 

Author Comment

by:Samooramad
ID: 12291822
ok I'll try it
0
 

Author Comment

by:Samooramad
ID: 12291915
do I use
class myContainerListener extends adapter or listener?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12292036
class MyContainerListener implements ContainerListener {
    // methods
}
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 400 total points
ID: 12292041
class myContainerListener extends ContainerAdapter {

    public void componentAdded(ContainerEvent e) {
    }
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12292049
ContainerAdapter implements ContainerListener
An abstract adapter class for receiving container events.
The methods in this class are empty.
This class exists as convenience for creating listener objects.   // <<<<<<<< ;°)
0
 

Author Comment

by:Samooramad
ID: 12292116
this whole adapter, listener thing is still quite new to me zzynx.. I don't really get it or the whole implements concept :)
ok I'll see what I end up with
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12292258
Well, it's not that difficult.

You should just have

1)
class MyContainerListener extends ContainerAdapter {

     private JPanel thePanel = null;

    public MyContainerListener(JPanel p) {
         super();
         thePanel = p;
    }

    public void componentAdded(ContainerEvent e) {
        // call the your method here.
        // Of course I don't know on which object it is called.
        // I supposed it is called on your panel. That's why I passed it as a parameter.
        // This way you can now write:
        thePanel.myMethod();
    }
}

2) somewhere in your code you have to make your listener listen:

    yourPanelOnTheEast.addContainerListener( new MyContainerListener(yourPanelOnTheEast) );

That's it ;°)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12292260
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12292264
;-)

Since you only have a couple of methods in the interface, it's better to implement it than to extend an adapter, as you 'use up' your single inheritance
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 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