🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #8418

Re: Multiple Event Listeners For One event

#8418
From: David Jefferson
Date: Wed, 16 Aug 2000 00:00
47 lines
1910 bytes
One way would be to define your listener's method to have a boolean return
value (true for event handled, false otherwise), then in your fireEvent
method when you are enumerating through the listeners as soon as one of them
returns true then you can return ie something like this:

public interface MyListener
{
    public boolean handleEvent(MyEvent e);
}

// -------------------- In class which listeners are listening
to ---------------------

private void fireEvent(MyEvent e)
{
    for (Enumeration enum = m_listeners.elements(); enum.hasMoreElements();)
    {
        MyListener myListener = (MyListener) enum.nextElement();
        if (myListener.handleEvent(e)) return;
    }
}

The other, related model which is quite cool is vetoable change listeners
which may be appropriate.

Dave

"Ali Demir" <demir.4@osu.edu> wrote in message news:399a025d$1_2@dnews...
> Hello,
>
> I have Multiple Event Listeners For One event. If one of the listeners
> handles the event, I would like other listeners to skip this event.
>
> Is there a recommended way of implementing a design pattern so that this
> kind of problem is nicely handled?
>
> For example it would be nice if the event class had a property which I
could
> set to 'handled'...
>
> All advice is welcome.
> Thank you in advance.
>
> Ali Demir
> demir.4@osu.edu
>
>
Technical Details
Message-ID: <399a8d44_1@dnews>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <399a025d$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,3998603c7ea30180
X-Google-Attributes: gid111d45,public
From: "David Jefferson" <david.jefferson@kbcfp.com>
Subject: Re: Multiple Event Listeners For One event
Date: 2000/08/16
Message-ID: <399a8d44_1@dnews>
X-Deja-AN: 658909750
References: <399a025d$1_2@dnews>
X-Trace: 16 Aug 2000 05:47:00 -0800, 194.203.209.252
X-MSMail-Priority: Normal
X-Priority: 3
Newsgroups: borland.public.jbuilder.java.swing
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700