The JavaTM Tutorial
Previous Page Lesson Contents Next Page 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 API documentation for the Java 2 Platform to answer these questions:
  1. The ClickMe component uses Color.BLACK when setting up its border. What other colors can you get by name like this?
  2. How would you create a Color object to represent purple? (Hint: Purple is made up of equal parts red and blue.)
  3. What Graphics method would you use to draw a filled square?
  4. What Graphics method would you use to draw text?

Exercises


Note: The point of these exercises is to encourage you to read code and to use the API documentation. We haven't yet given you any detailed information about how to write code, but you might be surprised at how much you can do.
Use what you learned from the preceding questions to make the following modifications to the ClickMe component.
  1. Modify ClickMe to draw a red square instead of a green spot.
  2. Modify ClickMe to display your name in purple instead of a green spot.

Remember that to compile and use the ClickMe component, you need the files ClickMe.java (in a .java source file), ClickMeApp.java (in a .java source file), and Spot.java (in a .java source file). You can run the program using the command java ClickMeApp.

Check your answers. (in the Learning the Java Language trail)

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.