Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Java. How can I fix my code so that it can fit these requirements: n is an i

ID: 3593021 • Letter: F

Question

For Java. How can I fix my code so that it can fit these requirements:

n is an integer that will be entered by a user in a JTextField

Add a JLabel prompt so the user will know what to enter in the text field

You must use the BorderLayout for the content pane in this application.

You can use the library method drawOval to draw an individual planet or create a more

advanced shape (i.e., using Polygon class).

Planets should be painted in random colors.

Use ActionEvent (button or text field) or MouseEvent to trigger drawing the planets.

my code:

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class Random1 extends Applet
{
public void paint (Graphics page)
{
int NumOfCircles = 100;
int diameter;
int x, y;
setBackground(Color.black);
Random generator = new Random();
for (int count = 0; count < NumOfCircles; count++)
{
diameter = generator.nextInt(60);
x = generator.nextInt(300);
y = generator.nextInt(500);

page.setColor(new Color(generator.nextInt(256), generator.nextInt(256), generator.nextInt(256)));
page.fillOval(x, y, diameter, diameter);
}
}}

Explanation / Answer

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class Random1 extends Applet
{
public void paint (Graphics page)
{
int NumOfCircles = 100;
int diameter;
int x, y;
setBackground(Color.black);
Random generator = new Random();
for (int count = 0; count < NumOfCircles; count++)
{
diameter = generator.nextInt(60);
x = generator.nextInt(300);
y = generator.nextInt(500);

page.setColor(new Color(generator.nextInt(256), generator.nextInt(256), generator.nextInt(256)));
page.fillOval(x, y, diameter, diameter);
}
}}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote