# [java] Giving applets Focus first

## Recommended Posts

Just a random question but just working on a simple pong game and when I load the applet within a html page, I firstly have to click on the applet to do anything on it. I know this isn't a major problem but just wondering if there is a way so when the page loads the applet is straight away under the player control? Unsure if this would be better placed within the html forum but hopefully it should be ok here. Thanks in advance. Nate

##### Share on other sites
I think there is some java script you can call to set the input focus on a page so that could be the place to start

:-)

##### Share on other sites
lol durr silly me, thanks for the reply and silly me for not thinking about that :P

Cheers

##### Share on other sites
irrc you can use the focus function of the DHTML applet tag in order to give focus to the applet though I am not sure if this will cause java to set the focus.

Example:
<applet      id="myapplet_id"     code="myapplet"     archive="mypackage.jar"     width=600     height=400     >Get java stupid!</applet>

And the javascript for the page
onload = document.all("myapplet_id").focus();

I think that should help! Let me know if that works!

##### Share on other sites
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/ieappletguide/

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627700
• Total Posts
2978695

• 21
• 14
• 12
• 10
• 12