Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Working Applet
Help and Hints
Source Code
Table of Contents
Online Training
shadowSearchFAQFeedback

ColorTest

Prerequisites

  • None.
In this exercise, you will write an applet that displays four colored Canvas objects using colors defined in the Color class.

Perform the following tasks:

  1. Create an applet called ColorTest that sets the layout manager to GridLayout(2,2).
  2. Define a class called ColorCanvas that is an extension of Canvas. Set the constructor to accept a Color object, that is stored in an instance variable. Define a lifecyle public void paint(Graphics g) method that sets g's color and fills a rectangle to the full extent of the Canvas. Hint: you can get the size of a Component with method size.
  3. In your applet, create and add four ColorCanvas objects with colors Color.black, Color.red, Color.orange, and Color.yellow.

Related Exercises

  • None