What's the best way to implement listeners?

W

Wilco van der Veer

I wondered if somebody might be able to help me at the following
problem:

I wrote an application which uses multiple JFrames. These frames are
instantiated from one class (which is the starting point of the
application).
Now I want to write an operation which can tell if the frame is
disposed in an efficient manner. (I don't want to rely on the
graphical events, but one something more reliable) I've been thinking
about creating listeners in the main class (from which the JFrames are
instantiated).

Does somebody know if such a thing is possible? Are there maybe any
other ways to handle te problem?

Thanks in advance!

Cheers,
Wilco
 
C

Chris Smith

Wilco said:
Now I want to write an operation which can tell if the frame is
disposed in an efficient manner. (I don't want to rely on the
graphical events, but one something more reliable) I've been thinking
about creating listeners in the main class (from which the JFrames are
instantiated).

I'm still a little unclear on what exactly it is that you want.
Certainly you can create listeners in the main class, and register them
to listen for events on the JFrame instances. Is that what you want?
If so, all you need is to write classes (nested or even anonymous
classes work fine) that implement the appropriate listener interface,
and as soon as you've created the JFrame, call the appropriate
addXXXListener method.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
W

Wilco van der Veer

Well, I wan't to respond on a function in the class without creating
an instance of the 2nd frame in the first frame itself.

The structure should look like this.

1 Main.class
- instantiates 1st frame
- instantiates 2nd frame
- makes first frame visible
- should listen if a function within the firstframe returns 'true' and
makes the 2nd frame appear (and disposes the first frame)

1 firstFrame.class
- does a something and return a true to a specific user-action

2 secondFrame.class
- does nothing

I hope someone can think of a solution to this problem. I can create a
loop in the first class which verifies continuely if the function
returns true (but that's inefficient and takes up a lot of CPU time)

Best Regards,
Wilco
 
C

Chris Smith

Wilco said:
I hope someone can think of a solution to this problem. I can create a
loop in the first class which verifies continuely if the function
returns true (but that's inefficient and takes up a lot of CPU time)

You need to determine what causes the function to return true, and
listen for changes to that. If you have control over the code for the
first frame, it should be rewritten to support this event-based
approach.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top