The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Learning the Java Language
Lesson: Object-Oriented Programming Concepts

## Questions and Exercises: Object-Oriented Concepts

> ### Questions

> > Use the javadocs to answer these questions:
> > 1. The ClickMe applet uses `Color.red` to set the drawing color to red. What other colors can you get by name like this?
> > 2. How would you specify other colors, like purple?

> ### Exercises

> > Now, use what you learned from the javadocs to make the following modifications to the `ClickMe` applet. To compile this program, you also need the ``Spot.java`` file.

> > > Note: This is an exercise in reading code, making guesses, and looking up classes and methods in the javadocs. We haven't yet given you any detailed information about how to write Java code and what it all means. But you might be surprised at how much you can intuit from the code. The main point of this exercise is to get you to use the javadocs and to read code. Do not worry if you cannot get your solution to work. Do not worry if your solutions do not match ours. Do compare your solutions to ours so that you can get more experience reading code and perhaps learn more about the API in the Java platform.

> > 1. Modify the applet to draw a green square instead of a red spot.
> > 2. Modify the applet to display your name in purple instead of a red spot.

> ### Extra Credit Exercises

> > Use the javadocs to find information to help you make these modifications to the `ClickMe` applet. To compile this program, you also need the ``Spot.java`` file.
> > 1. Modify the applet to erase the red spot instead of redrawing the whole applet.
> > 2. Modify the applet to drag the red spot when the mouse is held down and dragged.
> >    Hint: For this exercise, start with the result from the previous exercise (erasing the spot rather than redrawing the applet). You will have to clear the applet for each mouse pressed event, but for each mouse dragged event you can just erase the previous spot.
> > 3. Starting with your solution to the previous exercise, change the applet into a "scribble" applet, which draws as the mouse is dragged.
> >    Hint: You don't have to write any new code for this one!

> Check your answers.

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form