I'm trying to make an application that draws me several circles in a JFrame with multiple Threads but at the time of running the program only draws 2 circles and I can not find the problem if someone could support me I leave the code below.
package juego2;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Scanner;
import javax.swing.JFrame;
import java.util.Random;
public class simulacion extends JFrame implements Runnable {
Scanner scanner = new Scanner(System.in);
int cantidad;
int aleatoriox,aleatorioy,aleatoriox1,aleatorioy1;
public simulacion() {
System.out.println("¿# de Agentes?");
cantidad = scanner.nextInt();
Thread agentes[]= new Thread[cantidad];
for(int i=0;i<cantidad;i++) {
agentes[i] = new Thread(this);
agentes[i].start();
System.out.println("Hilo: "+i);
}
}
public void paint(Graphics g) {
aleatoriox = (int) (Math.random() * 375) + 15;
aleatorioy = (int) (Math.random() * 500) + 100;
aleatoriox1 = (int) (Math.random() * 375) + 15;
aleatorioy1 = (int) (Math.random() * 500) + 100;
g.drawOval(aleatoriox,aleatorioy,aleatoriox1,aleatorioy1);
}
public static void main(String[] args) {
simulacion frame = new simulacion();
frame.setSize(400,600);
frame.setVisible(true);
}
@Override
public void run() {
repaint();
}
}