jQuery in Action, 3rd edition
The moose likes Applets and the fly likes Applet games played with keys - getting the focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet games played with keys - getting the focus" Watch "Applet games played with keys - getting the focus" New topic

Applet games played with keys - getting the focus

Vlad Lato

Joined: May 04, 2009
Posts: 1
I've searched this forum for similar topics and found a few but they didn't help me, so I'm starting a new thread.
I have a small collection of logic games implemented as Java applets. Some of them are controlled with keys and the problem is that the game field is not getting the focus upon loading of the applet in the browser. I tried to overcome the issue by adding a call to requestFocusInWindow() in the init() and start() methods or in different event handlers (for example, in the handler for the New item of the game menu). That helped but not completely: I got consistent behavior in some browser+OS configurations and had no success in others. For example, on the same Windows machine I need to click the game field twice if I load the game with Opera and can play right upon loading if the same game is loaded with Internet Explorer. Could someone suggest me the best technique to get focus to a Canvas placed within the Applet's content panel? Maybe, there are some peculiarities I need to know? Currently, to work around the issue I make the user to select the New item in the game menu in order to start the game - but I don't like this way because most users expect the game to be ready to play once it is loaded and they see the game field. Moreover, this only works for 7 shapes and Snake but still doesn't enable the keys for 15 puzzle if I use Opera under Windows. If it helps, here you can play the games I'm talking about my games site.
Thank you in advance for your advices.

Best regards,
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

"Leo Taurus", please check your private messages for an important administrative matter.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: Applet games played with keys - getting the focus
It's not a secret anymore!