• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I get my applet to get focus?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to "Applets" forum.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic