wood burning stoves 2.0*
The moose likes Applets and the fly likes How do I get my applet to get focus? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "How do I get my applet to get focus?" Watch "How do I get my applet to get focus?" New topic

How do I get my applet to get focus?

Anton Westbergh

Joined: Mar 24, 2004
Posts: 5
I am writing a little Tetris-clone, which you can test here:
I have a problem. The applet doesn't get focus when entering the page, and you have to click it with the mouse before you can do anything. (Before it registers key-events and so on)
Can I help this with some simple JavaScript? Any help would be VERY welcome, since I don't have the time to learn all JavaScript tonight, and would very much like to get this fix done ;D
Best regards!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Moving to "Applets" forum.

[Jess in Action][AskingGoodQuestions]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Anton!
Allow me to continue Ernest's thought, and let's continue this conversation over in the Applets forum...
[ March 26, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
wayne hitchcock

Joined: Dec 22, 2003
Posts: 8
I've written a number of applets and found this to be a problem on some browsers, so what I suggest may or may not work.
In the applet class's init() method write:
If it works the applet will have focus. If your applet uses mnemonics be sure they are different from the mnemonics your browser uses because it is the browser's mnemonics that will be invoked.
Anton Westbergh

Joined: Mar 24, 2004
Posts: 5
Well, I tried this.requestFocusInWindow(); but it doesn't help..
You can see for yourselves at: www.elitris.com
Enter the page, and see what I mean. You must click the applet, or it doesn't get focus.
I agree. Here's the link: http://aspose.com/file-tools
subject: How do I get my applet to get focus?
Similar Threads
problem about using javascript to valide data
Frustrating compilation "Cannot resolve symbol" error
dynamically change Applet param via javascript
Applet/PHP/MySQL problems!
To create Java Puzzle game -Tetris