You do not want to write a game using swing components for sprites!
Most likely, you create a user control (usually obtained from JPanel or Canvas), and then override the paint () function.
Inside your drawing function, you draw your image as follows:
class MyClass extends JPanel{ int x,y; BufferedImage myImage = ImageIO.read("mySprite.png"); @Override public void paint(Graphics g){ g.drawImage(myImage,x,y,this); } }
Then in your code, you change the x and y values ββto move the sprite.
source share