Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSC171 — Exercise

Graphics

The goal of this assignment is to give you experience drawing with Java graphics. For each of the following questions, you need to define a class that extends JComponent and performs painting in its paintComponent method. I like to call these classes something like Canvas (or ending in Canvas), but it’s up to you. You also need a class containing a main method that demonstrates the use of your painting class within a JFrame.

Note that your drawing code must use the current width and height of the canvas to scale the drawing appropriately. You can test this by changing the the size of the window (which will cause paintComponent to be called again).

Questions

1.  Implement a canvas that draws red lines around all four edges, blue lines at the hori- zontal and vertical midpoints, and green lines across the diagonals.

2.  Implement a canvas that draws the pattern shown below, with lines fanning out from the top-left corner:

 

I suggest using a loop. One approach is to divide the width and height into a number of equal steps (I used 15 for mine). The lines all start at coordinates (0,0). The endpoint of the rst line is the bottom-left corner.  Each successive line’s endpoint is one step further horizontally and one step less vertically.

3.  Extend your canvas to draw the lines fanning out from all four corners, as shown below:

 

Note that if you do it right, you need to do very little additional computation since all four patterns are symmetrical. The starting points are easy—think about the endpoints.

4.  Implement a canvas that draws the pattern shown below:

 

The first line starts in the top-left corner and ends at the bottom one step over to the right. The second line starts one step down, and ends one step farther right. And so on.

5.  Extend your canvas to draw the pattern in all four corners, as shown below:

 

As before, this is not hard if you think about the symmetries.

6.  Implement a canvas that draws 12 concentric circles at its center, as shown below:

 

The innermost circle should have a radius of 10 pixels, and each successive circle should have a radius 10 pixels larger than the previous one. The circles should have different colors, or alternate colors, or cycle through colors (which is what I did above).

Grading Scheme

Equal weight for each part.

Doesnt compile or is trivial

< 50%

Compiles and is non-trivial

2 50%

Complete and correct with good style and comments

100%

Incomplete, incorrect, bad style, no comments

< 100%

Submission Requirements

Your submission MUST include a le named README .txt” with your name, your NetID, the assignment number, and your lab section. This le should explain anything we need to know about how to build and run your project.  In particular, be sure to explain how to run what parts of your submission for each question in the assignment.

Submit your solution as a single ZIP archive to BlackBoard before the deadline. Late homeworks will not be graded and will receive a grade of 0.

All assignments and activities associated with this course must be performed in accordance with the University of Rochester’s Academic Honesty Policy.