Swing - how to catch all events  
Author Message
st946tbf





PostPosted: 2004-1-7 11:21:00 Top

java-programmer, Swing - how to catch all events Programming in java for a while now, but I still have this silly
problem that I don't know if the experts has a simple answer.

I have a Swing app. Yes, simple stuff eh. Next, user logins to use
the app. If they don't do anything (mouse move, key press) for a
while, then I log out. The think is that detecting a mouse event, I
have to register with each of the tabpane of the app. I don't like
that. Also, I have to register with each components within the panel.
The same for keyboard. For keyboard, it seems I can register event
for just any component (with appropriate modifer to get the input map
and action map). However, I still have to register all keys which are
alot. I want the ability to catch the event from top down. Anyevent
would goes through my filters first. Would this be possible? How do
I solve this simple and common problem? Thank you very much in
advance.
 
Robert Olofsson





PostPosted: 2004-1-7 15:31:00 Top

java-programmer >> Swing - how to catch all events VD <email***@***.com> wrote:
: Programming in java for a while now, but I still have this silly
: problem that I don't know if the experts has a simple answer.

: while, then I log out. The think is that detecting a mouse event, I
: have to register with each of the tabpane of the app. I don't like
: that. Also, I have to register with each components within the panel.
: The same for keyboard. For keyboard, it seems I can register event
: ....

You probably want to look at this:
http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html#glasspane

/robo
 
Adam





PostPosted: 2004-1-7 15:45:00 Top

java-programmer >> Swing - how to catch all events > I have a Swing app. Yes, simple stuff eh. Next, user logins to use
> the app. If they don't do anything (mouse move, key press) for a
> while, then I log out. The think is that detecting a mouse event, I
> have to register with each of the tabpane of the app. I don't like
> that. Also, I have to register with each components within the panel.
> The same for keyboard. For keyboard, it seems I can register event
> for just any component (with appropriate modifer to get the input map
> and action map). However, I still have to register all keys which are
> alot. I want the ability to catch the event from top down. Anyevent
> would goes through my filters first. Would this be possible? How do
> I solve this simple and common problem? Thank you very much in
> advance.

About the keyboard you might want to look at
KeyEventPostProcessor
added to KeyboardFocusManager

Adam


 
 
st946tbf





PostPosted: 2004-1-8 2:42:00 Top

java-programmer >> Swing - how to catch all events Thank you all for helping me out. I haven't tried your solution yet,
I'll check them out though. Now, I got the solution that currently
works. I am not sure if it's a recommended way of doing things or
not, but very nice and easy to do. First, get a toolkit:

Toolkit toolkit = mycomponent.getToolkit();
toolkit.addAWTEventListener()... or something like this.

//void addAWTEventListener(AWTEventListener listener, long eventMask)

it takes 2 argument, the first one is the listener, the 2nd is the
long modifier which could be:

long mymodifier = AWTEvent.KEY_EVENT_MASK | MOUSE_EVENT_MASK |
MOUSE_MOTION_EVENT_MASK;

That would do it for me. This problem is so common that I think
almost any Swing GUI program will soon or later encounter it.

> > I have a Swing app. Yes, simple stuff eh. Next, user logins to use
> > the app. If they don't do anything (mouse move, key press) for a
> > while, then I log out. The think is that detecting a mouse event, I
> > have to register with each of the tabpane of the app. I don't like
> > that. Also, I have to register with each components within the panel.
> > The same for keyboard. For keyboard, it seems I can register event
> > for just any component (with appropriate modifer to get the input map
> > and action map). However, I still have to register all keys which are
> > alot. I want the ability to catch the event from top down. Anyevent
> > would goes through my filters first. Would this be possible? How do
> > I solve this simple and common problem? Thank you very much in
> > advance.
>