tags:

views:

173

answers:

2

I can not get that that super class is AWTEvent class or EventObject?

+2  A: 

Both. EventObject is AWTEvent's superclass. And AWTEvent is the superclass of many events that you'll use in day to day code. Most of the keyboard, mouse or basic user input events are AWTEvents. For the more specific Swing events, most of them extend EventObject -- though not all.

For example: ActionEvent extends AWTEvent which Extends EventObject

http://java.sun.com/javase/6/docs/api/java/awt/event/ActionEvent.html

EventObject is a very basic class, practically just the most basic of interfaces (although it's not actually an interface). AWTEvent is the class that actually handles the input events on a lower level. For the Swing classes that don't deal directly with hardware input events, they only need to extend the functionality provided by EventObject, so that's what they extend.

If you want to see which Events extend which classes go to the API's and browse the java.awt.event (http://java.sun.com/javase/6/docs/api/java/awt/event/package-frame.html) and javax.swing.event (http://java.sun.com/javase/6/docs/api/javax/swing/event/package-frame.html) packages to see which events extend which classes.

Daniel Bingham
Actually `AWTEvent` is not a base class of most Swing events. Swing is not known for being consistent.
Tom Hawtin - tackline
Right you are, most of the events I was thinking of were actually AWT Events and I'd never even noticed.
Daniel Bingham
AWTEvent is not a base class of **any** Swing events; AWTEvents are used only by AWT components. Swing is built on top of AWT, but it has many event classes that are completely independent of AWT. Why should they be subclasses of AWTEvent?
Alan Moore
That's not really correct - Swing components still make use of pretty much all the AWTEvent sub-classes defined in java.awt.event - ActionEvent, MouseEvent, KeyEvent, etc. - and some events defined in javax.swing.event do extend AWTEvent - however most events added in javax.swing.event are for listening to changes in a model - so just extend EventObject rather than AWTEvent.
Nate
A: 

Well, it would have to be EventObject, since it's the superclass of AWTEvent. More to the point, AWTEvent is, as the name implies, the superclass of all the built-in AWT event classes, while event classess in other parts of the standard libraries (including Swing) descend from EventObject directly. You can see all this for yourself by looking at the docs.

But this is really a tautology: What's the superclass of all event classess? The class they're all subclassed from, of course! What I've told you is true (AFAIK) for the standard libraries, but anyone can write a class that descends from any existing, non-final class and name it "SomethingEvent". Be careful not to read too much into names and class hierarchies.

Alan Moore