Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

binding keys to action

Thread view: 
George - 04 Dec 2005 18:23 GMT
hi,
i have an applet  and i want to bind an action if a key is pressed
how can i do that?

tia

george
George - 04 Dec 2005 19:06 GMT
oops sorry for the double post :(
zero - 04 Dec 2005 19:26 GMT
"George" <urdad@hotmail.com> wrote in news:1133720608.105362.322880
@g14g2000cwa.googlegroups.com:

> hi,
> i have an applet  and i want to bind an action if a key is pressed
[quoted text clipped - 3 lines]
>
> george

Add a KeyListener to the applet, check which key was pressed, and act
appropriately.

addKeyListener(new KeyAdapter()
{
  public void keyPressed(KeyEvent e)
  {
     // ...
  }
});

If the same action can be invoked through a menu or button click, you
should look into Actions.

class KeyAction extends AbstractAction
{
  public KeyAction(int mnemonic)
  {
     putValue(MNEMONIC_KEY, new Integer(mnemonic));
  }

  public void actionPerformed(ActionEvent e)
  {
     // ...
  }
}

Signature

Beware the False Authority Syndrome



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.