Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] Key listeners in Applets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 gdalston   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 January 2001 - 10:44 AM

I''m trying to add a key listener to my applet. I have this code inside of init(): addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { System.out.println("Key pressed."); } }); This should work. It works fine in an application. I can get mouse listeners to work using this same technique. I think the problem is that the applet doesn''t have the "focus" of the keyboard (e.g. when I use appletviewer to run it the keyboard controls the buttons at the top of the appletviewer.) Is there anyway to get around this problem? Thanks

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 31 January 2001 - 04:24 AM

call requestFocus() either in the init method of your applet, or
when a mouse click occurs.

#3 Neurotic   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 January 2001 - 06:01 PM

This is why often have a "please click on the applet before you play" comment next to most applet games.

The focus is not neccessarily on the applet, so it can''t register input events.

Mark




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS