Troubleshooting guide

23
1: Creating UIs
/* Constructs a button with specified label and shape, and the default style. */
public CustomButtonField(String label, int shape) {
this(label, shape, 0);
}
/* Constructs a button with specified label and style, and the default shape. */
public CustomButtonField(String label, long style) {
this(label, RECTANGLE, style);
}
/* Constructs a button with specified label, shape, and style */
public CustomButtonField(String label, int shape, long style) {
super(style);
_label = label;
_shape = shape;
_font = getFont();
_labelHeight = _font.getHeight();
_labelWidth = _font.getAdvance(_label);
}
/* Method that draws the focus indicator for this button and
* inverts the inside region of the shape.
*/
protected void drawFocus(Graphics graphics, boolean on) {
switch(_shape) {
case TRIANGLE:
int w = getWidth();
int h = w >> 1;
for (int i=h-1; i>=2; --i) {
graphics.invert(i, h - i, w - (i << 1), 1);
}
break;
case RECTANGLE:
graphics.invert(1, 1, getWidth() - 2, getHeight() - 2);
break;
case OCTAGON:
int x3 = getWidth();
int x = 5 * x3 / 17;
int x2 = x3 - x;
x3 = x3 - 1;
x2 = x2 - 1;
graphics.invert(1, x, getWidth() - 2, x2 - x + 1);
for (int i=1; i<x; ++i) {
graphics.invert(1+i, x-i,
getWidth() - ((i+1)<<1), 1);
graphics.invert(1+i, x2+i,
getWidth() - ((i+1)<<1), 1);
}
break;
}
}
/* Returns the label. */
public String getLabel() {
return _label;
}
/* Returns the shape. */
public int getShape() {