Motorola T720 Developer's Manual page 47

Hide thumbs Also See for T720:
Table of Contents

Advertisement

Coding Example
One thing to note is that we reduce the drawing rectangle's size by five pixels. This is so
that the button and its focus border (which must be slightly larger than the button) can be
drawn safely within the rectangle that comprises the actual component. If you draw
outside of the component's rectangle, a portion of the image is clipped.
The next section of code tests to see if the round button component has focus ownership
(isPressed() returns true). If so, the focus border circle i drawn using the drawing
rectangle's dimensions plus four pixels.
The code next tests to see if the button is in its pressed state. If so (isPressed()
returns true), then the button's fill color is set to black. Otherwise, the button is in its
normal state, and the fill color is set to gray.
// Paint the interior of the button with the chosen color
// Draw the perimeter of the button
if (isEnabled()){
} // end if
// Draw the label centered in the button
// Set color depending upon if button is depressed
} // end paint
This section of code draws the button's body. The fillArc() method paints an area
using the current color. Because the drawing rectangle that fillArc() works with is
actually a square in this case, which results in painting a circular area with the current
color.
The code tests to see if the button is enabled (isEnabled() returns true). If it is, a
black perimeter is drawn. Otherwise, the perimeter isn't drawn, so that the button appears
disabled.
g.fillArc(2, 2, s, s, 0, 360);
g.setColor(0, 0, 0);
g.drawArc(2, 2, s, s, 0, 360);
if (isPressed()){
g.setColor(255, 255, 255);
} // end if
else {
// black label (normal)
g.setColor(0, 0, 0);
} // end else
Font f = getFont();
g.drawString(label,
(s/2 - f.stringWidth(label)/2)+2,
(s/2 - f.getHeight()/2)+2,
Graphics.TOP|Graphics.LEFT);
// white label (pressed)
// Get typeface info
// Draw the text
47

Advertisement

Table of Contents
loading

Table of Contents