Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > What's the best way to implement listeners?

Reply
Thread Tools

What's the best way to implement listeners?

 
 
Wilco van der Veer
Guest
Posts: n/a
 
      04-27-2004
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
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      04-27-2004
Wilco van der Veer wrote:
> 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
 
Reply With Quote
 
 
 
 
Wilco van der Veer
Guest
Posts: n/a
 
      04-29-2004
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


Chris Smith <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)4.net>...
> Wilco van der Veer wrote:
> > 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.

 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      04-30-2004
Wilco van der Veer wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to implement extremely heavy calculation? roygon ASP .Net 10 04-07-2006 03:22 PM
Best way to implement custom control: Repeater vs. Anything Else =?Utf-8?B?V2ViTWF0cml4?= ASP .Net 3 12-09-2004 02:26 AM
what is the best way to implement a navigation David ASP .Net 1 06-03-2004 05:20 AM
Re: BEST WAY TO implement shopping basket Kevin Spencer ASP .Net 0 08-05-2003 04:23 PM
Re: Best way to implement ASP Session variables Steve C. Orr, MCSD ASP .Net 0 07-16-2003 09:09 PM



Advertisments