ColorTest
Prerequisites
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:
Create an applet called ColorTest that sets the layout manager to GridLayout(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.
In your applet, create and add four ColorCanvas objects with colors Color.black, Color.red, Color.orange, and Color.yellow.
Related Exercises
|