|
-
Oct 1st, 2001, 05:20 AM
#1
Thread Starter
Randalf the Red
Event Hierarchy
I think the event hierarchy is a bit too much on the Everything Is A Class bandwagon. It could better be implemented like MS.
Any opinions?
.
-
Oct 1st, 2001, 06:03 AM
#2
Member
Everything's class-happy in Java.
-
Oct 1st, 2001, 10:24 AM
#3
Dazed Member
Not quite sure what you mean. Are you talking about the
java.awt.event classes? The adapter classes, listeners, and the event classes?
-
Oct 1st, 2001, 08:56 PM
#4
Thread Starter
Randalf the Red
Well ...
Exactly.
If I create a class in VB and want to associate some events with it, I just need to create a public event procedure and I am done.
If I want to trap an object's events in my code, I need to write the procedure declared as public event handler inside the object in my code.
But look at Java. You need to create a class that implements a listener, then you have to override all the methods inside that listener, whether or not you need those events, and finally register it with the class which will receive the events. SO much work!
Mind ya, I am trying to get something out in favour of Java by criticizing it. Just my way of knowing things better.
.
-
Oct 3rd, 2001, 10:07 AM
#5
Dazed Member
It really matters what kind of event you are trying to trap.
Low level events or semantic events "high level". I noramlly dont use a listener for low level events because of the need to provide multiple method implemations. It just doesnt make sense unless you are trapping multiple events. I do use listeners for high level events like ActionListener,AdjustmentListener,ItemListener, TextListener because there is only one method defined for each listener. For low level events i use adapter classes this way i just have to override the nessary method needed.
For instance...... say if you want test for window closing events on a JFrame. You can either implement a WindowListener interface or extend "subclass" the WindowAdapter class. If you
implemented the WindowListener interface then you would have to provided a method signature in your class for seven methods
which would be a pain in the A@#.
-
Oct 5th, 2001, 11:11 AM
#6
Thread Starter
Randalf the Red
Well ...
I look at it this way:
In VB when I have to trap a particular event for an object, all I do is write a public sub (sort of overriding) for that event as specified by the object.
In Java, even if I want to trap the existing events, I have to go create a listener, register it and then override all its methods, as you pointed out.
Couldn't Java implement events the way MS did/does? And if not, why?
.
-
Oct 5th, 2001, 12:14 PM
#7
Dazed Member
If you extend or "subclass" an adapter class then
all you have to do is override the necessary method.
For high level events it really doesnt make a diffrence if you implement a listener or subclass an adapter class because
of the small amount of events that you can trap. Java is true
OOP so obviously the creation of a subprocedure wouldnt make sense in terms of trying to mimic Visual Basic. I dont know i dont
see it as being much work to trap events in Java.
-
Oct 5th, 2001, 12:52 PM
#8
Thread Starter
Randalf the Red
Well ...
Yes, the OOP has been very strictly (I would say a little too strictly) implemented in Java.
It's both an advantage and a disadvantage. From VB point of view, it's just a bit complicated to get used to, while from an OOP point of view, it's just the logical way to go.
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|