import java.awt.*;
import java.util.Random;
import javax.swing.*;
public class RandomImage extends JFrame implements Runnable {
private JLabel label;
private ImageIcon image;
private Random random;
public RandomImage() {
super("Random Image");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setResizable(false);
setLocationRelativeTo(null);
label = new JLabel();
add(label);
image = new ImageIcon("path/to/roza.png");
random = new Random();
}
public void run() {
while (true) {
int x = random.nextInt(getWidth() - image.getIconWidth());
int y = random.nextInt(getHeight() - image.getIconHeight());
label.setIcon(image);
label.setBounds(x, y, image.getIconWidth(), image.getIconHeight());
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
RandomImage app = new RandomImage();
app.setVisible(true);
new Thread(app).start();
}
}