• Post Reply Bookmark Topic Watch Topic
  • New Topic

applet focus

 
D Miller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a JApplet with a KeyListener associated with it. The applet is a simple test; to start the applet the user simply pushes the space bar. This works fine except that before pressing the space bar, you must first click on the applet to give it focus.
Is there any way to easily give the applet focus (to get the applet ready to accept keystrokes) without having to click on the applet?
 
Caven Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would u like to try using JavaScript . on body loaded, make the applet "object " is onfocus!
 
D Miller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I tried to use javascript but still could not get it to work. I tried the following in the body's onload tag.

but the focus() method is really for a text box is suppose.
You said onfocus but I was unsure how to do that.
Any other suggestions would be great. Thanks.
 
Caven Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to insert applet as an object and set its ID. You may call the ID in your js.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!