Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fig. 8.19 | Creating a JFrame to display a DrawPane1. (Part 2 of 2.) GUI and Graphics Case Study Exercise 8.1 Extend the program in

image text in transcribed
Fig. 8.19 | Creating a JFrame to display a DrawPane1. (Part 2 of 2.) GUI and Graphics Case Study Exercise 8.1 Extend the program in Figs. 8.17-8.19 to randomly draw rectangles and ovals. Create classes yRectangle and Myoval, Both of these classes should include xl,y1, x2, y2 coordinates, a color and a flag to determine whether the shape is filled. Declare a constructor in each class with argu- ments for initializing all the instance variables. To help draw rectangles and ovals, each class should ovide methods getUpperLeftx, getupperLeftY, getwidth and getHeight that calculate the upper- left x-coordinate, upper-left y-coordinate, width and height, respectively. The upper-left x-coordinate is the smaller of the two ax-coordinate values, the upper-lef y-coordinate is the smaller of the two y- coordinate values, the width is the absolute value of the difference between the two x-coordinate val- ues,and the height is the absolute value of the difference between the two y-coordinate values. Class DrawPanel, which extends JPanel and handles the creation of the shapes, should declare three arrays, one for each shape type. The length of each array should be a random number berween 1 and 5. The constructor of class DrawPane1 will fill each array with shapes of random position, size, color and fill. In addition, modify all three shape classes to include the following ) A constructor with no arguments that sets the shape's coordinates to 0, the color of the shape to Color.BLACK, and the filled property to false (MyRectangle and MyOval only). b) Set methods for the instance variables in each class. The methods that set a coordinate value should verify that the argument is greater than or equal to zero before setting the coordinate-if it's not, they should set the coordinate to zero. The constructor should call the set methods rather than initialize the local variables directly. c) Get methods for the instance variables in each class. Method draw should reference the coordinates by the get methods rather than access them directly

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

Students also viewed these Databases questions

Question

List the commonly used accuracy metrics for KNN.

Answered: 1 week ago

Question

3 The distinction between microeconomics and macroeconomics.

Answered: 1 week ago

Question

2 The role of economic theory in economics.

Answered: 1 week ago