I am going to try a few ways I’ve seen, they are all very different, but I want to know what is your favorite way to do it 
What is easy?
What is efficient?
What is the best for games?
I am going to try a few ways I’ve seen, they are all very different, but I want to know what is your favorite way to do it 
What is easy?
What is efficient?
What is the best for games?
I’m interested with this answer too ;D.
I did my own system for my game but I’m not sure if it’s the best. What I did is basically putting a KeyListener in my JFrame than this KeyListener send the character data it receive as an event to all my Object. Than I create a class call KeyController and I associate one to every Object. The KeyController receive the data sent by the KeyListener in the JFrame than check if this data (character) correspond to an action and if yes modify the Object.
I really just take the easiest road here, so it might be the worse method (I don’t know) but it works.
http://www.google.com/search?hl=en&q=how+to+get+keyboard+input+in+java&btnG=Google+Search&aq=f&oq=
this is a very simple thing.
post back after you read it.
I find it slightly ironic that you would make a reply like that, h3ckboy. 
For keyboard input, I usually make a keyboard handler class that listens to keyboard events from my game component (usually a JComponent or a Canvas). When a key is pressed, I mark it as pressed in a boolean[], when it is released, I unmark it.
I can also forward specific key events from there to ensure individual key presses don’t get missed in a low framerate situation (very very frustrating for the user).
If an event requires the user to keep a key pressed (like moving a character), I use the boolean[]. If it should trigger on a single key press (like entering letters into a chat, or activating hyperspace, or whatever), I use the actual key listeners.
Keep in mind that just forwarding the key events from the awt event dispatcher thread can cause synchronization problems, so a more complex solution would be to queue all key presses (or rather, key types) into a list, then request them every frame from the game thread.
One thing to keep in mind is that you will not get key release events if your component doesn’t have keyboard focus. This is a very common problem in many games, including “Big” titles. So I usually add a focus listener as well, and unset ALL keys when the focus is lost.
Yeah I was thinking abouit that as I posted.
For the record though I had already googled it.
I would have found it except I didnt know it was called vector math.
back on topic:
ok, so if oyu are using java 2D, you can implement keyListener, try to compile it will explain the rest :).
you can name the variables it specifies anything oyu want.
GL.
P.S: what oyu never seen a hypocrite b4 
I do much the same thing except that I use an enum to store the key state as either UNPRESSED, PRESSED, RELEASED_AND_UNPRESSED, or RELEASED_AND_PRESSED.
For some keys, I check whether they’ve been released, and for others I check whether they’re currently pressed.
I “solved” this problem by only having one JFrame containing one JPanel with no other Swing components. I use my own custom widgets inside of the JPanel. That’s a somewhat extreme solution, but there were other things I was trying to deal with as well.
An alternative would be to use JInput. I’ve tried it out for keyboard input, but it doesn’t seem to be any particular improvement. I plan to use JInput for reading gamepad input, KeyListener for keyboard input, and MouseListener for mouse input. The KeyListener will be implemented as described above.
Edit: I should mention that my custom widgets don’t work that way except for the main game widget For the other widgets, I just send the key event to the focused widget like Swing would do. I actually overrode the regular key input method for my main game widget to store the presses and releases. Since the main game widget is the only focusable widget visible while you’re playing the game, I didn’t need to worry about redirecting the input to other widgets within the main game widget.
oh, sorry for delayed response, I think either my key input is perfect and my movement is bad, or the key input is bad.
I added a class for a keylistener, and it flips booleans on or off for up, down, right, left in the main class.
In the main class I have this to repeat:
for(;;)
{
if (down && right)
{
//change the image to fit the direction he is going
sprite.setImg("sprite_rd.png");
//move him one pixel for each direction he is going
sprite.setXY(sprite.getX()+1,sprite.getY()+1);
}
else if (up && right)
{
//etc...
sprite.setImg("sprite_ru.png");
sprite.setXY(sprite.getX()+1,sprite.getY()-1);
}
else if (down && left)
{
sprite.setImg("sprite_ld.png");
sprite.setXY(sprite.getX()-1,sprite.getY()+1);
}
else if (up && left)
{
sprite.setImg("sprite_lu.png");
sprite.setXY(sprite.getX()-1,sprite.getY()-1);
}
else if (down)
{
sprite.setXY(sprite.getX(),sprite.getY()+1);
sprite.setImg("sprite_d.png");
}
else if (up)
{
sprite.setXY(sprite.getX(),sprite.getY()-1);
sprite.setImg("sprite_u.png");
}
else if (right)
{
sprite.setXY(sprite.getX()+1,sprite.getY());
sprite.setImg("sprite_r.png");
}
else if (left)
{
sprite.setXY(sprite.getX()-1,sprite.getY());
sprite.setImg("sprite_l.png");
}
//update
sprite.repaint();
}
I guess now that I have keys responding very quickly, there are two problems:
-he moves very fast >.<
-the cpu usage is really high even when he isn’t doing anything because it is looping constantly and going through the if-statements.
you need to have it check only once every... 5 milliseconds.
like this:
if(System.currentTimeMillis() - lastReload > 5)
{
lastReload = System.currentTimeMillis();
//all taht chekcing stuff
}
if problem persists, jsut increas the amount of time it has to wait.
You should have some kind of waiting mechanism in your loop to limit the frame rate. I won’t go into details here: you can find examples in the resources page for the 4k contest forum.
okay it works now, my lagg problem is fixed with a 1ms thread sleeping.
It laggs when attempting to refresh the images constantly, like 10000fps so I need to limit it since it won’t ever do that good, it just laggs.