Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Key Adapter  RSS feed

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My applet for compile and I don't understand why. This is my code:


This is my html:



These are my errors:
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The import statement does not import members of subpackages.

You have to explicity import those classes.

import java.awt.event.*;
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I get this error:
 
Keith Lynn
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like a problem with your drive.
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the driver problem... and it compiles fine. Why doesn't it move at the press of the up and down keys?
 
Keith Lynn
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using keyTyped instead of keyPressed. I'm not sure if that will fix the problem, but it might.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are using KeyAdapter(), which means the required methods of the KeListener
interface are pre-written (empty), and you override the method/s you want

public void KeyPressed (KeyEvent keP)
does not override
public void keyPressed (KeyEvent keP)//small k

instead it creates a new method, so that when the KeyListener comes looking
for keyPressed(..), it finds an empty method and does nothing

when you get these fixed, you may also have to click into the applet,
to ensure it has the focus.
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not understanding! If you mean that keP has lowercase k, then I changed it to uppercase (and I didn't think it would make a difference)it still doesn't work.
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your not doing the class thing right again...

public class upndownAdapter extends KeyAdapter
{
public void keyPressed(KeyEvent event)
{}
public void keyReleased(KeyEvent event)
{}
}



and you have to define for all directional keys..

up,down,left,right.

if left and right don't do anything, define them as empty...

but when you do

addKeyListener(new KeyAdapter())

you have to make a new adapter...

like so

addKeyListener (new KeyAdapter(upndownAdapter));


that should fix it...

-Justin-
[ April 26, 2006: Message edited by: Justin Fox ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the methods are
keyPressed(..) small k
keyReleased(..) small k, and with a d

and I'll re-add
when you get these fixed, you may also have to click into the applet,
to ensure it has the focus.

if it still doesn't work, change the KeyAdapter to KeyListener, add an empty
keyTyped(), and the compiler will tell you when you have it right

[edit]
and when you do get it right, up goes down, down goes up.
[ April 26, 2006: Message edited by: Michael Dunn ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!