Begin working with graphics in Java. More practice reading and applying the API documentation and writing Javadocs.
Your programming work for this assignment must be done in the IntroToJavaGraphics
project inside Eclipse. Use the SVN Repository Exploring
perspective to check out this project, then switch back to the Java
perspective.
Release your inner Van Gogh: But keep your ears, we hope.
You should do your programming for this task in the MyViewer
and MyComponent
classes that we started together in class.
Complete a “work of art” using shape classes that we used in class, plus at least one class from the java.awt.geom
package that we didn’t use together. (There are some wild classes in that package. Arc2D.Double
and RoundRectangle2D.Double
are probably the most straightforward of the classes we didn’t cover yet.)
You’ll probably find this task easier if you sketch your drawing on paper first. That way you won’t be trying to be artistic while also trying to master the Java classes.
Circle of Circles: Your work for this problem should be done in the classes CircleOfCircles
and CirclesComponent
. I suspect you’ll find this problem substantially more challenging than the ones so far.
When the main()
method of CircleOfCircles
is run the program should ask the user for three numbers (see hint below):
Your program then draws a “Circle of Circles” pattern like the ones in the figures below. The centers of the individual circles are equally spaced around the “big circle”. The “big circle” isn't actually drawn. Note that the “big circle” may, in fact, have a smaller radius than the individual circles.
Here are some tips to get you started:
main()
method of CircleOfCircles
are available in the paintComponent()
method of CircleComponent
. But you still have to collect the inputs and assign them to the provided variables.
JOptionPane
: String input = JOptionPane.showInputDialog("Enter the big radius:"); double bigRadius = Double.parseDouble(input);
Math
class of the java.lang
package. For example, you can calculate the sine of π/2 like this: Math.sin(Math.PI/2.0)
. See the API Documentation for more details.
for
loops in Java are almost exactly like C, except we can declare a variable in the loop initializer. For example: for (double d = 0.0; d < max; d += stepSize) { // do something here }
Here are some example outputs:
Turn-in your programming work by committing it to your SVN repository.