Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming Use the following files: JFrame.java RandomStarComponent.java import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; public class RandomStarComponent extends JComponent { private static final long serialVersionUID

Java Programming

image text in transcribed

image text in transcribed

Use the following files:

JFrame.java

 

RandomStarComponent.java

import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; public class RandomStarComponent extends JComponent { private static final long serialVersionUID = 1L; public void paintComponent(Graphics g) { // Recover Graphics2D Graphics2D g2 = (Graphics2D) g; RandomStar star = new RandomStar(100, 100, 50, 25); star.draw(g2); RandomStar star2 = new RandomStar(100, 200, 40, 60); star2.draw(g2); RandomStar star3 = new RandomStar(100, 300, 40, 30); star3.draw(g2); } } 

RandomStarViewer.java

import javax.swing.*; public class RandomStarViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("RandomStar"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); RandomStarComponent component = new RandomStarComponent(); frame.add(component); frame.setVisible(true); } }
Create a class RandomStar which models a star burst of random lines radiating in all directions from a given point. The constructor takes the x, y coordinates of the center of the star, the maximum distance of the x and y coordinates of the radiating lines from the center of the RandomStar, and the number of lines to draw. The draw method takes the graphical context as a parameter. It draws the specified number of lines Each line has one end point at the center of the RandomStar. The other end has x and y coordinates each of which are less than the maximum distance specified from the center. Your output will look like this RandomStar Complete the following file: RandomStar.java 1 public class Randomstar 2 3 private Random gen; 4 6 public Randomstar(int x, int y, int maxDistance, int numberOfLines) 8 9 gen new Random(987654321); /7.. your code 10 12 13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions