File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Author

Applet games played with keys - getting the focus

Vlad Lato
Greenhorn

Joined: May 04, 2009
Posts: 1
Hi,
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,
Vlad
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Applet games played with keys - getting the focus
 
Similar Threads
A Loading bar for mobile game!
Anyone wants to join our new gameproject
Popup lists
JInternalFrames and focus
Problem in Opening JPopupMenu