Ok guys. I'm making a game. For now I made a program in which you can move ball with arrow keys. UP, DOWN, RIGHT and LEFT.

My first question is:I clicked one button... Ball moves... but not instantly!! I just hate this. Like it's somehow delayed or something. At key click it moves only for 5 sources than it moves normally. But I want that ball moves constantly... Try it out with my code. How to make ball moving nice and without dalaying?

My second question is:I can move left and right, up and down. how to move up and left at the same time? when I click Up and Left keys I want that ball moves up and left. not just left or just up. how to do that?

What's happening is the OS only allows one key to fire the event at a time. When you hold down one key then press a second one, it stops calling the fire for the first one.You need to keep track of which button is pressed, by setting a boolean. Then add the keyReleased to your KeyAdapter. Set the boolean to true on the key press and false on the key release. In your paint you will have to add to your movement. See this post a while back.http://www.java-gaming.org/topics/trouble-getting-started/23664/msg/196970/view.html#msg196970

What's happening is the OS only allows one key to fire the event at a time. When you hold down one key then press a second one, it stops calling the fire for the first one.You need to keep track of which button is pressed, by setting a boolean. Then add the keyReleased to your KeyAdapter. Set the boolean to true on the key press and false on the key release. In your paint you will have to add to your movement. See this post a while back.http://www.java-gaming.org/topics/trouble-getting-started/23664/msg/196970/view.html#msg196970

ok ty i'll try this. Do you know how to solve problem with delayed painting?

Once you implement the boolean method this will fix the pausing when you first press the button.

I'd actually like to know why this would fix the delay? Is it because he's not using the standard keyPressed/keyReleased instead of his method? I actually doubt that would be the problem, but I can't see the reason as to why it would be delayed on his first key press.

He is using keyPressed just using it in a strange way, see line 28. The reason it causes such odd behavior is because the keyPressed is only called at the computers typematic rate and also it's called from a different thread, the boolean method described above fixes both of these.

On a side note I noticed an infinite loop bug on line 41, your missing an = or better yet remove the comparison because running is already a boolean.

For 2nd question, use help of dx and dy variabel and update your ball position through these variabels. They will control the movement direction and speed. If you make your game loop right, it should be moving diagonal.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org