Step 7


Overview

In this step, you will be adding code to your classes to handle new drawing methods and their parameters. You will write a fair amount of code, but it can be easy if you take the time to understand what you are doing. It can be easy because you have done it all before, so you have existing code to work with as an example.

There are three substeps, each described in its own section below.

Handle New Drawing Method Parameters

There are 6 new drawing method parameters that are needed: width, height, arc width, arc height, start angle, and arc angle. Like the x and y drawing method parameters that you already have, these all have type int and are all controlled by JSlider controls.

In order to handle each new drawing method parameter, you need to do the following.

After making these changes, you should recompile the two classes. If you get any errors, they are most likely due to inconsistent spellings of variable or method names or omission of their declarations. You can also run the applet with appletviewer. You should see all of the new controls, but they will not have any effects on the drawings until after the next substep.

Handle New Drawing Methods

There are 8 new drawing methods that are needed.
Drawing Method Name
drawRect
drawOval
drawRoundRect
drawArc
fillRect
fillOval
fillRoundRect
fillArc

You will deal with each of these drawing methods in the same way that you are now dealing with the drawString drawing method.

After making these changes, you should recompile the two classes. If you get any errors, they are most likely due to inconsistent spellings of variables or omission of their declarations. You can also run the applet with appletviewer. The controls should affect the drawing in the draw panel, but the title in its border will not be correct. That will be fixed in the next substep.

Incorporate New Drawing Method Parameters into the Draw Panel Title

The last thing you need to do in this step is add some if statements into the changeTitle() method in the DrawPanel class. These statements should incorporate the appropriate parameters into the message local variable. They should be added just before the statement that appends the close parenthesis and semicolon. Here are the rules for appending parameters to message.

After making these changes, you should recompile the DrawPanel class and run the applet with appletviewer. Now the draw panel title should be correct. Do you have the commas in the right place? Your applet should look like the following demonstration applet. Check all of the controls to make sure they are working correctly.

Demonstration Applet