By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Creating Key Listeners for JAVA

P: n/a
Hi Everyone,

I have created a Java Applet that creates shapes, but I need help
with code to make them move Left, Right, Up, and down. I am using a
IDE called NetBeans, and created a "formKeyPress" to help with the
movement on the applet form area. However, I have no idea what code to
use. This is how the "formKeyPress" looks like:

private void formKeyPressed(java.awt.event.KeyEvent evt) {
}

Can anyone help me? Please, please please....
Rafael
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sp***@rloteck.com (Rafael) wrote in message news:<a5**************************@posting.google. com>...
Hi Everyone,

I have created a Java Applet that creates shapes, but I need help
with code to make them move Left, Right, Up, and down. I am using a
IDE called NetBeans, and created a "formKeyPress" to help with the
movement on the applet form area. However, I have no idea what code to
use. This is how the "formKeyPress" looks like:

private void formKeyPressed(java.awt.event.KeyEvent evt) {
}

Can anyone help me? Please, please please....
Rafael


public class MyApplet extends Applet implements KeyListener{

public void init(){
...
...
addKeyListener(this);
...
...
}

...
...
public void keyPressed(KeyEvent e){
//See KeyEvent javadoc.
//If the key is VK_LEFT move the shape to the left, etc.
//Change the parameters and call repaint()
}
...
...
}
Jul 17 '05 #2

P: n/a


"Rafael" <sp***@rloteck.com> wrote in message
news:a5**************************@posting.google.c om...
Hi Everyone,

I have created a Java Applet that creates shapes, but I need help
with code to make them move Left, Right, Up, and down. I am using a
IDE called NetBeans, and created a "formKeyPress" to help with the
movement on the applet form area. However, I have no idea what code to
use. This is how the "formKeyPress" looks like:

private void formKeyPressed(java.awt.event.KeyEvent evt) {
}

Can anyone help me? Please, please please....
Rafael


JAVA [sic] is not an acronym, Java is a programming language.

You shouldn't using NetBeans if you don't understand the fundamentals of the
language.
I suggest you read up on interfaces.

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
(2003 VTR1000F)
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.