Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why wont my handleKeys method function and allow me to control the patrol ship?  RSS feed

 
Chris Terranova
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a Java newbie working on a space invaders program. When I call my method handleKeys it does not function properly and allow me to control the patrol ship with the left and right arrow keys. Any help would be appreciated.

 
Carey Brown
Saloon Keeper
Posts: 2536
33
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say that "it does not function properly" what do you mean? Explain what you are doing and what your program is doing in response.

Line 64: why are you passing in the various Arrow paramters? You are not using them. Ditto on line 36.

What is a "DrawingPanel"? Can you post the code for this?
 
Carey Brown
Saloon Keeper
Posts: 2536
33
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your design is based on the AWT package which is old and has been replaced by Swing. Your design should be event driven not polling loops with sleeps. Events in your case would probably be just keyboard events. You can add a KeyListener to your JPanel. You can use Swing's Timer class to call a method to move the various bits of graphics.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You can add a KeyListener to your JPanel.

That could do it, but Swing was designed to work with Key Bindings.

And since this is about GUIs, I'm moving the thread to a more appropriate section.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!