Remember not to create packages. Use the default package
In these problems, you will revisit problems from hw2 and represent the shapes with classes so that multiple objects can be drawn.
There are only 2 problems this week.
Note: for a quirky reason, the viewer class must import javax.swing.*; rather than javax.swing.JFrame. Ask me if you want an explanation.
4A
In this problem you will write a Rainbow
class which will draw a "rainbow" at a specified (x, y).
Rainbow
will have a construct that takes the x, y coordinates of the upper-left hand corner of the rainbow as well as the height of a color.
Rainbow
will have a draw method which takes the graphical context as a parameter and draws the rainbow.
The rainbow will be displayed as colored rectangles rather than arcs. The height of a rectangle is given in the constructor. The width of a rectangle is 5 times the height of a rectangle. The colors of the first 5 should be made with the pre-defined colors in the Color class. Use red, orange, yellow, green, and blue in that order. The next color is indigo and has RGB values (75, 0, 130). The last rectangle is violet with RGB values of (143, 0, 255). You will need to construct Color objects using these values. There are 7 rectangles.
You will complete the RainbowComponent
class to construct and draw three Rainbow objects given these criteria
RainbowViewer
is provided.
4B
In this application, you will create a Target
class. A target consisting of three concentric circles with specifications listed below
The constructor takes the x, y coordinates of the center of the target and the radius of the smallest circle.
Follow these specifications
You will complete the TargetComponent
class to construct and draw two Targets objects given these criteria
The center is at 50, 60. The small radius is 15
The center is at 30, 150. The small radius is 5
TargetViewer
is provided.