Check for applet keyboard focus?

Is there a way for an applet to determine if it’s got the keyboard focus or not? I would like to display a “game paused, click to resume” message to the user when it looses focus. I’ve tried to implement FocusListener, but focusGained() and focusLost() don’t seem to do anything. Anyone know of a way to check for focus in an applet?

java.awt.Component has a hasFocus() method which returns true if the component has the keyboard focus. Applet inherits from Component so you can use that method in your Applet.

EDIT: However be careful if you have another component overlaying the applet, then you will have to call that Component’s hasFocus() method.

Sweet, if(this.hasFocus()) works perfectly for what I need. You’re all right. I don’t care what everyone else says about you. :wink:

O_o what do people say about me?!

I think he refers to my comment on your awkwardness rating :wink:

Riven, you’re making me look bad :’(

Oh come on. You were the one pleading for a medal. You gotta expect some counter force.

;D