• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

keyevent not working in applet?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just started creating this portal game and I've encountered no problems except that KeyEvent isn't doing anything. Here's my code so far (in two classes):



and the second class:



Help please?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add "keyaction" as KeyListener to the component that should listen to key events.
 
ajay smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do I put that in/how do I do that? Kinda confused
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like "addKeyListener(new keyaction())". You would do that in the init method. The thinkerbox method you should delete entirely. And the keyaction class needs to override one (or more) of the 3 methods it defines, not create a new method. And it must not create a new instance of the portal class.

Start by reading http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html to get some understanding how key listeners work.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AWT was superseded by Swing more than 10 years ago. I recommend you change to Swing, which means extending JApplet instead of Applet and gaining a basic understanding of the component hierarchy imposed by the RootPaneContainer interface. Then you can leverage Swing's Key Bindings which afford much more flexibility than a simple KeyListener.

db
 
reply
    Bookmark Topic Watch Topic
  • New Topic