PaintWindow pw = new PaintWindow(); Random rand = new Random(); ImageIcon image = new ImageIcon("C:/Users/Ghostkilla/Desktop/gubbe.jpg"); setWidth(pw.getBackgroundWidth()); int height = pw.getBackgroundHeight(); int dx = -3; int dy = 0; int x = 250; int y = rand.nextInt(height-100); while(true) { pw.showImage(image, x, y); PaintWindow.pause(20); x += dx; y += dy; if(x<0) { dx = -dx; dx = -dx;
If you run this code it will move a picture from right to left and hit the left wall and then go to right again leaving the window (It stops there). I want to make so it hits left and then right wall continuesly till someones close the window. So basically im using a for loop to make it go left right all the time and i need help.
Also I dont know how to make so the picture moves from bottomleftcorner to toprightcorner diagonally without leaving the window.