Skip to main content

Relationship between KeyEvent and FocusEvent

2 replies [Last post]
Joined: 2008-06-13

Hi Gents,

It seems that a KeyEvent is translated to FocusEvent or ActionEvent inside AWT. Hence I don't need to register any KeyEvent listener and can have my component response to a key action as long as it is registered as FocusEvent or ActionEvent listener.

The same to MouseEvent as long as the player has mouse support and the Xlet are using AWT UI widgets.

I'm really curious: What's the detailed mechanism that a KeyEvent is translated to a FocusEvent or ActionEvent? Any recommended articles on this are also appriciated.



Message was edited by: szmarine

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-11-08


If you want to learn about different event types, I'd look for books. I don't know about a good online doc for it. For focus, meanwhile, there's a famous focus subsystem spec.

In general, KeyEvent/FocusEvent/ActionEvent all exist for different purposes, and while one event can cause another to follow, I do not think one event can be transformed to another.

KeyEvent is generally sent to the AWT component that is the current focus owner (currently has a focus on the screen). So, if a component registers FocusListener and KeyListener, then a FocusEvent.FOCUS_GAINED is expected to be delivered before that component starts receiving KeyEvents.

ActionEvent is a semantic event which can be triggered from user's input events (KeyEvent/MouseEvent) only under certain conditions. For example, java.awt.Button can receive ActionEvent, and it's event generation is likely to be decided on the Button peer's native code level. In PBP, I believe the only way for AWT components to receive ActionEvent is to implement AWTEventMulticaster. KeyEvent, being a lower level event, provides more info of what has occurred. If your code need to know which remote control button is pressed by the user, for example, then I believe it needs to implement KeyListener.

I hope it helps.


Joined: 2008-06-13

Hi Chihiro,

This is Great! Thanks a lot for you reply and patience.