public BitmapButtonField(Bitmap normalState, Bitmap focusState, long style) {
    super(Field.FOCUSABLE | style);

    if ((normalState.getWidth() != focusState.getWidth())
        || (normalState.getHeight() != focusState.getHeight())) {

      throw new IllegalArgumentException("Image sizes don't match");
    }

    _bitmaps = new Bitmap[] {normalState, focusState};
  }
  public SliderField(
      Bitmap thumb,
      Bitmap sliderBackground,
      Bitmap sliderBackgroundFocus,
      int numStates,
      int initialState,
      int xLeftBackMargin,
      int xRightBackMargin,
      long style) {
    super(style);

    if (initialState > numStates || numStates < 2) {}
    _imageThumb = thumb;
    _imageSlider = sliderBackground;
    _imageSliderFocus = sliderBackgroundFocus;
    _numStates = numStates;
    setState(initialState);

    _xLeftBackMargin = xLeftBackMargin;
    _xRightBackMargin = xRightBackMargin;

    _rop = _imageSlider.hasAlpha() ? Graphics.ROP_SRC_ALPHA : Graphics.ROP_SRC_COPY;

    _thumbWidth = thumb.getWidth();
    _thumbHeight = thumb.getHeight();

    initBitmaps();
  }
 private void copy(Bitmap src, int x, int y, int width, int height, Bitmap dest) {
   int[] argbData = new int[width * height];
   src.getARGB(argbData, 0, width, x, y, width, height);
   for (int tx = 0; tx < dest.getWidth(); tx += width) {
     for (int ty = 0; ty < dest.getHeight(); ty += height) {
       dest.setARGB(argbData, 0, width, tx, ty, width, height);
     }
   }
 }
  /**
   * Field implementation.
   *
   * @see net.rim.device.api.ui.Field#paint(Graphics)
   */
  protected void paint(Graphics graphics) {
    // First draw the background colour and picture

    switch (Display.getWidth()) {
      case 480:
        graphics.drawBitmap(12, 10, dbmp.getWidth(), dbmp.getHeight(), dbmp, 0, 0);
        graphics.drawBitmap(167, 10, ibmp.getWidth(), ibmp.getHeight(), ibmp, 0, 0);
        graphics.drawBitmap(324, 10, tbmp.getWidth(), tbmp.getHeight(), tbmp, 0, 0);
        graphics.setFont(font);
        graphics.setColor(Color.DARKSLATEGRAY);
        graphics.drawText(_dboc, 18, 40);
        graphics.drawText(_iboc, 173, 40);
        graphics.drawText(_tboc, 330, 40);
        break;
      case 360:
        graphics.drawBitmap(15, 10, dbmp.getWidth(), dbmp.getHeight(), dbmp, 0, 0);
        graphics.drawBitmap(185, 10, ibmp.getWidth(), ibmp.getHeight(), ibmp, 0, 0);
        graphics.setFont(font);
        graphics.setColor(Color.DARKSLATEGRAY);
        graphics.drawText(_dboc, 28, 40);
        graphics.drawText(_iboc, 198, 40);
        graphics.drawBitmap(15, 65, tbmp.getWidth(), tbmp.getHeight(), tbmp, 0, 0);
        graphics.drawText(_tboc, 130, 95);
        break;
      default:
        graphics.drawBitmap(15, 9, dbmp.getWidth(), dbmp.getHeight(), dbmp, 0, 0);
        graphics.drawBitmap(166, 10, ibmp.getWidth(), ibmp.getHeight(), ibmp, 0, 0);
        graphics.setFont(font);
        graphics.setColor(Color.DARKSLATEGRAY);
        graphics.drawText(_dboc, 18, 40);
        graphics.drawText(_iboc, 172, 40);
        graphics.drawBitmap(15, 65, tbmp.getWidth(), tbmp.getHeight(), tbmp, 0, 0);
        graphics.drawText(_tboc, 110, 95);
        break;
    }
  }
  /**
   * Cuts up the background image and margins you provide to make the left, center, and right
   * bitmaps
   */
  public void initBitmaps() {
    int height = _imageSlider.getHeight();

    _imageSliderLeft = new Bitmap(_xLeftBackMargin, height);
    _imageSliderCenter =
        new Bitmap(_imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height);
    _imageSliderRight = new Bitmap(_xRightBackMargin, height);

    copy(_imageSlider, 0, 0, _xLeftBackMargin, height, _imageSliderLeft);
    copy(
        _imageSlider,
        _xLeftBackMargin,
        0,
        _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin,
        height,
        _imageSliderCenter);
    copy(
        _imageSlider,
        _imageSlider.getWidth() - _xRightBackMargin,
        0,
        _xRightBackMargin,
        height,
        _imageSliderRight);

    _imageSliderFocusLeft = new Bitmap(_xLeftBackMargin, height);
    _imageSliderFocusCenter =
        new Bitmap(_imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height);
    _imageSliderFocusRight = new Bitmap(_xRightBackMargin, height);

    copy(_imageSliderFocus, 0, 0, _xLeftBackMargin, height, _imageSliderFocusLeft);
    copy(
        _imageSliderFocus,
        _xLeftBackMargin,
        0,
        _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin,
        height,
        _imageSliderFocusCenter);
    copy(
        _imageSliderFocus,
        _imageSlider.getWidth() - _xRightBackMargin,
        0,
        _xRightBackMargin,
        height,
        _imageSliderFocusRight);
  }