



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




To draw an arbitrary regular polygon:
circle, evenly spaced.The vertex points lie along the circumscribed
Each point is 2
(^) n (^) radians from the next point
(where
n (^) is the number of polygon sides). This
makes it easy to write a
(^) for
(^) loop to get the
2 vertices in polar coordinates (loop from 0 to ).
coordinates (r,(from Trigonometry) To translate from polar
) to rectangular (x, y):
(^) x = Math.cos(
) * r
(^) y = Math.sin(
) * r
The
(^) x , y pairs will be relative to the center, so
you’ll need to add the
x , y (^) offsets from the text
fi elds, then plug each pair into a
GeneralPath
r
Your class will need model fields for Details:
centerX
centerY
sides
radius
fillColor
, and
outlineColor
to pass data from the listeners to the
paintComponent(Graphics)
method.
then callWhen “Draw” is clicked, copy all text fields into member fields of your class,
repaint()
on the drawing component. To convert the
String
results
s of
JTextField.getText()
to an
int
, call
Integer.parseInt(s)
new color containing the user-chosen value. The (The color picker starts from the color passed as an argument and returns a Outline Color", oldColor); Color newColor = JColorChooser.showDialog(button, "Choose To display a color picker, call something like:
button
argument is the
JButton
that caused the
JColorChooser
to be shown.
JColorChooser
is in
the
javax.swing
package. Make the appropriate changes to the above in the
case of the fill color button.)