Write a Java application that draws a pattern in the output window that is drawn
with a for
loop, and is drawn in successive stages based on the
number of times the user has clicked on a button on screen. For an example
of how your program should work,
click here.
You should have
a for
loop in the paintComponent
method of MUPanel that will draw one
or more shapes, and will be executed howMany
times. You will need some
combination of g.setColor
, g.drawRect
,
g.fillRect
, g.drawOval
,
g.fillOval
, g.drawArc
and/or g.fillArc
method calls to draw
your assigned pattern. After the shapes are drawn inside the for
loop,
the values of the variables over
, down
, width
and/or
height
may need to be changed, based on how your assigned pattern changes.
Each student in the class has a unique pattern to work on — you MUST use the pattern that has been assigned to you for this project.
Hint: for this pattern, you will want to set the line width in the paintComponent
method to 3. You can do this by inserting the following two statements in your paintComponent
method immediately before the for
loop heading:
Graphics2D g2d = (Graphics2D) g; g2d.setStroke( new BasicStroke(3) );See the Changing the Line Thickness Demo for more information.
Convert your
CSC120\Java\PA5 folder into a .zip file named PA5.zip
and submit it to the PA5 dropbox
in D2L.
Evaluation Item | Possible points |
---|---|
CSC 120, PA 5, name, date, & description comments in MUPanel.java | 3 |
One private data member: an
Integer named numberOfReps or something similar. |
1 |
constructor sets numberOfReps to 1. |
1 |
for loop in the paintComponent method that draws
one or more shapes, and is executed numberOfReps times. |
3 |
A combination of g. methods used to draw your assigned pattern. | 4 |
After shapes are drawn inside for loop, over ,
down , width and/or height are
changed to make pattern change. |
6 |
One button causes numberOfReps to increase by one. Other
button causes numberOfReps to be reset to 1.
|
1 |
Pattern is correctly drawn, and matches the pattern assigned to the student. | 8 |
Organization and readability of the Java code, including appropriate indenting | 3 |
Total Points ====> | 30 |