Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I get my applet to get focus?

 
Anton Westbergh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a little Tetris-clone, which you can test here:
http://members.chello.se/foobar/anton/projektarbetet/source/Tetris%200.7/
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!
/Anton
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to "Applets" forum.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
wayne hitchcock
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
this.requestFocusInWindow();
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
regards
/Anton
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic