Problems with Java’s Paint method, ridiculous refresh velocity

  • The image fondo should already be scaled to 1200×600.
  • I am not sure, but is super.paint(g) needed? You might also use paintComponent.

The event handling (you seem to be moving by 1 pixel on key down), must be done correctly. I would have set the direction and speed (1px), and leave it to a swing timer to do the continuous moving.

Repainting best is done resilient/flexible: repaint(20L) (50 frames per second);
events like key-down maybe with EventQueue.invokeLater(new Runnable() { ... });.

Especially you might use repaint with the changed area.

Leave a Comment