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
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); } }}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started