Java Reference
In-Depth Information
LISTING 4.9
continued
//-----------------------------------------------------------------
// Color accessor.
//-----------------------------------------------------------------
public Color getColor ()
{
return color;
}
//-----------------------------------------------------------------
// X accessor.
//-----------------------------------------------------------------
public int getX ()
{
return x;
}
//-----------------------------------------------------------------
// Y accessor.
//-----------------------------------------------------------------
public int getY ()
{
return y;
}
}
The Splat program embodies fundamental object-oriented thinking. Each
circle manages itself and will draw itself in whatever graphics context you pass it.
Each Circle object maintains its own state. The Circle class is defined in a way
that can be used in other situations and programs.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 4.26 Where is the “content” of the panel created in the SmilingFace
program defined?
SR 4.27 In the SmilingFace program, when and how is the paintComponent
method of the panel object invoked?
SR 4.28 Write code that will add a pair of eyeglasses to the smiling face.
SR 4.29 Rewrite the constructor for the Circle class so that it generates a
circle with a random diameter that is between 20 and 200 inclusive for
the Circle object it sets up. The other attributes of the circle should
be provided as parameters to the constructor.
 
Search WWH ::




Custom Search