Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Java GUI Lesson 12 | Moving Graphics with arrow keys

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
11,171
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Apr 10, 2010

teaching how to move a circle around with the arrow keys

Link to this comment:

Share to:

Uploader Comments (macheads101)

  • Hey how can you count the number of times the arrow keys have been pressed can you help me with this please i really need it, Please and thank you

  • @ComputerKing240 Just have an integer variable that you increment (add one to) every time the key event is fired.

  • I have a question, why did you need to have another application out for the JFrame and main method? you cant combine it all into one application?

  • @scottyy888 If by application you mean class, you do not have to. Your main class could be a subclass of JFrame, but in general this is not good practice. Therefore, it's best to split your code up between multiple classes.

  • the method to keep it from going off screen would be the window size?

  • @malakov5 no i go over keeping it from going off screen in the previous tutorial

see all

All Comments (46)

Sign In or Sign Up now to post a comment!
  • How can i stop the graphic from moving after i press a key??? pls help tnx

  • @RockerNamedJoe same here

  • @RockerNamedJoe You need to repaint();

  • How do I make a black background?

  • @Hoobes1 Did you import it from javax.swing?

  • Eclipse doesn't like the start() method for t. I don't know why, but I personally don't see a start() method it can refer to. It says "The method start() is undefined for the type Timer".

  • Mine moves but it leaves footprints. How to fix?!?

  • Oval doesn't move on my side. Can somebody please share a link to full source code so i can compare. Thank you very much!

  • @Lt0Th3M Same here

  • @MinecraftingDaddio In your keyReleased(KeyEvent e) method set vely and velx to 0. That way whenever you stop holding a key down your velocities will be 0.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more