Java Reference
In-Depth Information
SR 4.28
There are many ways to add a pair of eyeglasses to the smiling face. The
following code, inserted after the code that draws the nose and mouth,
is one approach.
page.drawOval (BASEX+17, BASEY+23, 21, 21); // glasses
page.drawOval (BASEX+42, BASEY+23, 21, 21);
page.drawLine (BASEX+3, BASEY+27, BASEX+17, BASEY+27);
page.drawLine (BASEX+62, BASEY+27, BASEX+76, BASEY+27);
page.drawLine (BASEX+39, BASEY+29, BASEX+42, BASEY+29);
SR 4.29
The following code implements the requested constructor:
//---------------------------------------------------
// Constructor: Sets up this circle with the
// specified values.
//---------------------------------------------------
public Circle (Color shade, int upperX, int upperY)
{
diameter = ( int ) (Math.random() * 180) + 20;
color = shade;
x = upperX;
y = upperY;
}
It might be better to define and use constants of 180 and 20 in the
Circle class, or perhaps pass those values to the constructor from the
client as arguments.
4.7 Graphical User Interfaces
SR 4.30 Events usually represent user actions. A listener object is set up
to listen for a certain event to be generated from a particular
component.
SR 4.31
No, we cannot add any listener to any component. Each component
generates a certain set of events, and only listeners of those types can be
added to the component.
4.8 Buttons
SR 4.32
A JButton object generates an action event when the button is pushed.
When that occurs, the actionPerformed method of the action listener
associated with that button is invoked.
SR 4.33
To change the PushCounterPanel class so that instead of displaying a
count of how many times the button was pushed it displays a count
Search WWH ::




Custom Search