Troubleshooting guide
22
BlackBerry Java Development Environment Development Guide
Code sample: Creating custom buttons
Example: CustomButtonField.java
/**
* CustomButtonField.java
* Copyright (C) 2001-2005 Research In Motion Limited. All rights reserved.
*/
package com.rim.samples.docs.custombuttons;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
/**
* CustomButtonField is a class that creates button fields of various
* shapes. This sample demonstrates how to create custom UI fields.
*/
public class CustomButtonField extends Field implements DrawStyle {
public static final int RECTANGLE = 1;
public static final int TRIANGLE = 2;
public static final int OCTAGON = 3;
private String _label;
private int _shape;
private Font _font;
private int _labelHeight;
private int _labelWidth;
/* Constructs a button with specified label, and the default style and shape. */
public CustomButtonField(String label) {
this(label, RECTANGLE, 0);
}
Add component
capabilities.
> Implement the Field set() and get() methods.
public String getLabel() {
return _label;
}
public int getShape() {
return _shape;
}
public void setLabel(String label) {
_label = label;
_labelWidth = _font.getAdvance(_label);
updateLayout();
}
public void setShape(int shape) {
_shape = shape;
updateLayout();
}
Task Steps