I have an exercise in school where you are meant to change the code so that the image moves. The problem is that the image doesn't show in the first place and I don't know why. Here is the code:
public void exercise1e() {
Random rand = new Random();
ImageIcon image = new ImageIcon("images/gubbe.jpg");
PaintWindow_GU1.showWindow(600, 400, "P1", Color.WHITE);
PaintWindow_GU1.addSound("Skor", "sounds/trasiga_skor.mp3");
PaintWindow_GU1.playSound("Skor");
int width = PaintWindow_GU1.getBackgroundWidth();
int height = PaintWindow_GU1.getBackgroundHeight();
int dx = -2;
int dy = 1;
int x = 250;
int y = rand.nextInt(height-100);
PaintWindow_GU1.addIcon("Gubbe", image, 250, y, true);
while(true) {
PaintWindow_GU1.setIconXY("Gubbe",x,y);
PaintWindow_GU1.pause(20);
x += dx;
y += dy;
if(x<0) {
dx = -dx;
}
}
}