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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!