Here is the program that draws random circles on the screen using the JAVA language. package disegno; import java.awt.*; import javax.swing.*; public class Tela extends JPanel{ public void paintComponent(Graphics g) { super.paintComponent(g); this.setBackground(Color.WHITE); g.setColor(Color.BLACK); DisegnaCerchiA_Caso(3,10000,g); } public void DisegnaCerchiA_Caso(int raggio,int numeroCerchi,Graphics g) { int x,y; int numero=0; while(numeroCerchi>0) { x=(int)(Math.random()*1000); y=(int)(Math.random()*1000); g.setColor(Color.BLACK); if (IsPrime(numero)==1) { g.setColor(Color.RED); g.drawOval(x, y, raggio, raggio); } else { g.drawOval(x, y, raggio, raggio); } numero++; numeroCerchi--; } } public int IsPrime (int n) { int primo=1; int fattore=2; boolean exit=false; if (n==1) {exit=true; primo=0;} while(fattore<=n/2 && !exit) { if (n%fattore==0) { primo=0; exit=true; } fattore ++; } return primo; } } here is the result. In red, I highlighted the prime numbers. Rare between 0 and 10000. here is the file where you find the main: package disegno; import javax.swing.*; public class Disegno { public static void main(String[] args) { JFrame t= new JFrame("Grafica Iterativa"); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Tela p = new Tela(); t.add(p); t.setSize(1000, 1000); t.setVisible(true);
} } To put the code into function, follow the following video
🤖
Studio Assistito con l'Intelligenza Artificiale
Vuoi padroneggiare al meglio i concetti di questo articolo? Avvia lo studio assistito per generare riassunti automatici, mappe concettuali o farti interrogare con il metodo socratico.
🎯 Scegli l'Agente AI
Come preferisci studiare questo articolo?
📝
Riassuntore
Genera un riassunto strutturato dell'articolo
🧠
Schematizzatore
Crea mappe concettuali e schemi gerarchici
🎓
Tutor Socratico
Ti interroga sull'articolo con domande progressive