Discussion Locked

Simplify Event/Listener coding

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
The Jan. 13, Java TechMail discusses the Notifier Class. Will you be able to simplify your Event/Listener coding using the Notifier Class?

2 replies

by solrak29

I didnt' find this tip complete as I tried to test the code, but it seems that the ActionEvent object does not have a simple constructor as noted in the document. Thus, made this article incomplete and code unusable.....

Can you help?

by bayard-generationjava

That's true. You caught me being vague and hypothetical in my "Wouldn't it be nice".

java.awt.event.ActionEvent doesn't have a constructor which takes (Object), although the ultimate ancestor class java.util.EventObject does. Instead it has ActionEvent(Object, int, String), so replace

notifier.notify( new ActionEvent(this) );

with

notifier.notify( new ActionEvent(this, 0, "foo") );

The Event itself is relatively unimportant for the concept of Notifier as it just gets passed around, but the lack of compiling is a pain I admit. EventObject is the important class, ActionEvent is just an implementation.

This discussion is closed to new replies.