Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keydown listerner for applet

Status
Not open for further replies.

Bygbobbo

Programmer
Apr 23, 2002
145
US
I am trying to trap the keydown and keyup from an applet... Can anyone give me some advice/sample...

THanks in advance,

Bygs
 
Hi Bygbobbo,
The easiest way to get the event when a button has been clicked is to use
Code:
KeyListener
s. Simply implement the
Code:
KeyListener
interface and add it to the component(s) you'd like to listen to
Code:
KeyEvent
s on via the
Code:
addKeyListener (KeyListener)
method. Like this:
Code:
  someComponent.addKeyListener (someKeyListener);
The methods required to implement the KeyListener are as follows:
Code:
  public void keyTyped (KeyEvent event) {} 
  public void keyPressed (KeyEvent event) {} 
  public void keyReleased (KeyEvent event) {}
The
Code:
KeyEvent
object can give you all the data you need, including modifiers like alt, ctrl, etc.

Hope this Helps,
MarsChelios
 
yes it does help..

I was having a problem of where to add the:

addKeyListener(this);

I put this in the init()

Im grabbing all the keys that i need now thanks

Bygs :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top