Trying to do the programming task 1. When the program is running, 5 circles (random color, size and position) should be drawn. I thought I’d try to draw a circle first…but it turned out to be two! why? It seems that there is something in the code that needs to be “removed”, but what? Sorry for the slang in the comments.
Very grateful for the help.
This is my code:
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JFrame;
import java.util.Random;
public class Rita extends JFrame
{
public Rita()
{
setTitle("Rita");
setSize(960, 960);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
// Initierar ett random object
Random rand = new Random();
// loop to draw cicles
//for (int i = 0; i<5; i++);
//Initierar random color
int red = rand.nextInt(256);
int green = rand.nextInt(256);
int blue = rand.nextInt(256);
Color randomColor = new Color (red, green, blue);
// Generate random circle width 50 and X pixels
int width = rand.nextInt(201) + 20;
// Generate random X/Y koordinater
int radius = (int)(Math.random()*49) + 2;
int x = (int)(Math.random()*(960-radius*2) + radius);
int y = (int)(Math.random()*(960-radius*2) + radius);
//int x = rand.nextInt(960);
//int y = rand.nextInt(960);
// set the color
g.setColor(randomColor);
// Draw the circle
g.fillOval(x, y, width, width); // aka rita oval, storlek
}
public static void main(String[] args)
{
Rita rita= new Rita();
rita.paint(null);
}
}

Graham Greene is a contributor to Dealmakerz, covering news, politics, business, technology, sport, entertainment, and lifestyle. He focuses on clear, accurate reporting and useful information that helps readers stay informed about current affairs and developments that matter to them. His work highlights relevant stories, emerging trends, and key issues, presenting them in a balanced, accessible, and reader-friendly way.

More Stories
Millions of Samsung Galaxy Phones Set to Receive Free One UI 9 Upgrade
Samsung Galaxy Z Fold 8 Wide: Tech Giant Targets New Foldable Market With Slimmer Design
Fitbit Air Review: Google’s AI-Powered Health Tracker Takes Aim at Whoop