0
我爲BlackBerry項目創建了自定義按鈕字段。我想在繪製後改變按鈕上顯示的圖片,但不知道如何。我有更改存儲位圖的成員變量的代碼,但不知道如何告訴黑莓更新它。黑莓,創建了一個自定義按鈕,並希望圖像在顯示後更改圖像
// CODE TO CHANGE BUTTONS Image
Bitmap image2 = Bitmap.getBitmapResource("aftera.png");
MyBut.image=image2;
// don’t know how to redraw buttn?????
// BUTTON CODE
public class cPictureButton extends Field{
public Bitmap image;
public cPictureButton(Bitmap image, long style)
{
super(style);
this.image=image;
}
public int getPreferredHeight()
{
return image.getHeight();
// return getFont().getHeight();
}
public int getPreferredWidth()
{
return image.getWidth();
// return getFont().getAdvance(label)+8;
}
protected void drawFocus(Graphics g, boolean on)
{
}
protected void paint(Graphics g)
{
int w=image.getWidth();
int h=image.getHeight();
g.drawBitmap(0, 0, w, h, image, 0, 0);
if (isFocus())
g.drawRect(0,0,image.getWidth(), image.getHeight());
}
protected void layout(int width, int height) {
// TODO Auto-generated method stub
setExtent(Math.min(width, getPreferredWidth()),
Math.min(height, getPreferredWidth()));
}
public boolean isFocusable() {
return true;
}
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(0);
return true;
}
}
你好,謝謝你的幫助悠逸。是的,我花了一些東西,不得不把我的源代碼恢復到更新版本。你也知道任何好的書來編程黑莓。我通過閱讀差異文章來學習,這些文章並不能完全展現大局。 – 2011-05-23 21:45:38