applet focus

Is it possible to make an applet listen for input events automatically? I have to click on the applet window/awt frame (multiple times) to make it have focus and register input events.

The way im currently doing this is by adding the listners in the applet (and awt frame if i need to pop it up in a frame):

addKeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);

and define their implementation:

protected void processMouseEvent(MouseEvent evt)
{
<>
super.processMouseEvent(evt);
}

protected void processMouseMotionEvent(MouseEvent evt)
{
<>
super.processMouseMotionEvent(evt);
}

protected void processKeyEvent(KeyEvent e)
{
<>
super.processKeyEvent(e);
}

And another one, is it possible to have an awt frame receive mouse events outside of its frame?

Thanks!

As far as I know, whatever you do to get focus inside your java code, the applet itself still needs to get focus by clicking on it.
The easiest way I suppose to handle this is to make the user click on the applet, a “Click here to start” message in your game for example. Maybe you can give the applet focus with some nifty javascript in your webpage, but I never tried that…

No. Allowing an applet to steal focus from under the user would be a serious security risk.

erikd: thanks, I’ll look into the javascript thing.

I guess receiving mouse events (like position etc) outside an awt frame would fall under the same security issues as stealing focus? :-\

If your applet is signed (and if i remember well) it can request for focus.

I think there are some issues with old browser (netscape version < 6.0) but none with current ones.

Tell us is you find something

Lilian

AH. I didnt know that had been added. It makes sense that a signed Applet would be allowed to.

thanks :slight_smile:

JK