# Lab 2 Wrap-Up, Methods Exercise

Tom Kelliher, CS 116

Sept. 20, 2000

### Announcements

1. Friday's quiz covers Chapter 2.

2. Lab 2 due Friday.

3. Postlab programming exercises due Monday, Sept. 25. Hand-in hardcopy.

4. Third programming exercise available. ``Alphabetical ordering'' not important. Uniqueness is.

Lab 2.

### Outline

1. Lab 2 wrap-up: comments, discussion.

2. Methods Exercise: shaded ball method.

### Coming Up

Introduction to widgets.

# Lab 2 Wrap-Up

1. Setting colors in `drawHole()`:
```private void drawHole(int n, Graphics g)
{
int X0 = 50,   // x-anchor
Y0 = 50,       // y-anchor
W0 = 350,      // initial width
H0 = 200,      // initial height
X_INC = 30,    // x-anchor increment
Y_INC = 10,    // y-anchor increment
RG_INC = 10,   // red-green increment
BLUE_INC = 25; // blue increment

g.setColor(new Color(n * RG_INC,
n * RG_INC,
(n + 1) * BLUE_INC));

g.fillOval(X0 + n * X_INC, Y0 + n * Y_INC,
W0 - n * X_INC, H0 - n * 2 * Y_INC);
}
```
1. Restrictions on the arguments passed to the `Color` constructor.

2. ``My text won't display'' problems.

4. Declaring and using variables.

Remember: the computer knows nothing. It cannot figure out what you want to occur. You must instruct it, step by step.

2. The programming exercise: See the `java.awt.Graphics` class description in Section 2.8.

3. Dealing with a blank applet. If you see this error message at the bottom of AppletViewer:
```Start: applet not initialized
```
Exit AppletViewer and in JWS do the following: Open the Project menu, choose Properties, and look at the Run tab. Check that the Main Class Name entry matches your class name, including capitalization.

# Method design Exercise

Working in your lab groups, design a Java Method to produce a shaded ball like this:

Use the following signature for your method:

```void drawBall(Graphics g, int x, int y, int radius)
```
where `x` and `y` are the center of the largest circle.

Thomas P. Kelliher
Tue Sep 19 14:36:26 EDT 2000
Tom Kelliher