What's the best way to implement listeners?

Discussion in 'Java' started by Wilco van der Veer, Apr 27, 2004.

  1. 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
    Wilco van der Veer, Apr 27, 2004
    #1
    1. Advertising

  2. Wilco van der Veer

    Chris Smith Guest

    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
    Chris Smith, Apr 27, 2004
    #2
    1. Advertising

  3. 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 <> wrote in message news:<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.
    Wilco van der Veer, Apr 29, 2004
    #3
  4. Wilco van der Veer

    Chris Smith Guest

    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
    Chris Smith, Apr 30, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD

    Re: Best way to implement ASP Session variables

    Steve C. Orr, MCSD, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    364
    Steve C. Orr, MCSD
    Jul 16, 2003
  2. Kevin Spencer

    Re: BEST WAY TO implement shopping basket

    Kevin Spencer, Aug 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    398
    Kevin Spencer
    Aug 5, 2003
  3. David
    Replies:
    1
    Views:
    322
    Steve C. Orr [MVP, MCSD]
    Jun 3, 2004
  4. C-man
    Replies:
    0
    Views:
    399
    C-man
    May 24, 2004
  5. Matt Kruse
    Replies:
    2
    Views:
    171
Loading...

Share This Page