java里面的暂停按钮_如何在黑莓java中创建像youtube一样的播放/暂停按钮?

import java.util.*;

import net.rim.device.api.system.*;

import net.rim.device.api.ui.*;

import net.rim.device.api.ui.component.*;

import net.rim.device.api.ui.container.*;

import net.rim.device.api.system.Bitmap;

public class CustomImageButtonApp extends UiApplication

{

static Bitmap image;

public static void main(String[] args)

{

CustomImageButtonApp app = new CustomImageButtonApp ();

app.enterEventDispatcher();

}

public CustomImageButtonApp ()

{

final imagebutton img_btn = new imagebutton("",Field.FOCUSABLE, "play.png",

"pause.png", 0x9cbe95);

MainScreen screen=new MainScreen();

pushScreen(screen);

screen.setTitle("title");

screen.add(img_btn);

}

public class CustomImageButton extends Field {

private String _label;

private int _labelHeight;

private int _labelWidth;

private Font _font;

private Bitmap _currentPicture;

private Bitmap _playPicture;

private Bitmap _pausePicture;

int color;

public CustomImageButton (String text, long style ,String playimg, String pauseimg, int color){

super(style);

_playPicture= Bitmap.getBitmapResource( playimg );

_pausePicture=Bitmap.getBitmapResource( pauseimg );

_font = getFont();

_label = text;

_labelHeight = _playPicture.getHeight();

_labelWidth = _pausePicture.getWidth();

this.color = color;

_currentPicture = _playPicture;

}

/**

* @return The text on the button

*/

String getText(){

return _label;

}

/**

* Field implementation.

* @see net.rim.device.api.ui.Field#getPreferredHeight()

*/

public int getPreferredHeight(){

return _labelHeight;

}

/**

* Field implementation.

* @see net.rim.device.api.ui.Field#getPreferredWidth()

*/

public int getPreferredWidth(){

return _labelWidth;

}

/**

* Field implementation.

* @see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)

*/

protected void drawFocus(Graphics graphics, boolean on) {

// Do nothing

}

/**

* Field implementation.

* @see net.rim.device.api.ui.Field#layout(int, int)

*/

protected void layout(int width, int height) {

setExtent(Math.min( width, getPreferredWidth()),

Math.min( height, getPreferredHeight()));

}

/**

* Field implementation.

* @see net.rim.device.api.ui.Field#paint(Graphics)

*/

protected void paint(Graphics graphics){

// First draw the background colour and picture

graphics.setColor(this.color);

graphics.fillRect(0, 0, getWidth(), getHeight());

graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);

// Then draw the text

graphics.setColor(Color.BLACK);

graphics.setFont(_font);

graphics.drawText(_label, 4, 2,

(int)( getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK ),

getWidth() - 6 );

}

/**

* Overridden so that the Event Dispatch thread can catch this event

* instead of having it be caught here..

* @see net.rim.device.api.ui.Field#navigationClick(int, int)

*/

protected boolean navigationClick(int status, int time){

if (_currentPicture == _playPicture) {

_currentPicture = _pausePicture;

// invalidate();

} else {

_currentPicture = _playPicture;

//invalidate();

}

//fieldChangeNotify(1);

return true;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值