Java GUI Lesson 11 | Moving a Graphic

learning how to simply make a graphic move in the next tutorial we will me moving it with the arrow keys


  1. Calling t.start() in paintComponent isn't a very good idea.
    f.setVisible(true) implicitly calls paintComponent, which then calls t.start(), leading to repaint().
    repaint() schedules a call to paintComponent, which later calls t.start() again.
    You are basically starting the timer over and over again, it's much better for it to be started only once.

  2. the f.add(s) doesn't work. it says "The method add(Component) in the type Container is not applicable for the arguments (s)"
    is it possible for you to give solution how it worked in your program?

  3. Thank you!!!!! You are the first person on YouTube who explained this properly! I've been through dozens of videos and I'm glad I found yours.

  4. why does it seem like the circle goes slightly beyond the upper y boundary into the bottom of the frame?

  5. I think your videos are a great help, but if you are teaching people how to code in Java, then you should teach them cleaner code. Class names should start with a capital letter. Instead of using the literal value 40 you should use a final static. Something like public final static int BALL_W = 40; Is a better approach. In a big program if you wanted to change the size of the ball you might need to update 100's of lines of code and it would save you a lot of time if you used a final static instead. Please don't think I am trying to pick holes in your video, it's just that these things are pretty important.

  6. I Finished the code but when i came to run it an error came up and it said "second cannot be resolved to a type"

    How do i fix this?

  7. Hey one more thing – my balls leaves a solid black trail behind it looking line a snake growing longer and longer.  I followed the code, any idea why this is happening?

Leave a Reply

Your email address will not be published. Required fields are marked *