【问题标题】:Blackberry, created a custom button and would like image to change image after it is draWN黑莓,创建了一个自定义按钮,并希望图像在绘制后更改图像
【发布时间】:2011-05-23 14:41:57
【问题描述】:

我为我的 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;
}

}

【问题讨论】:

    标签: blackberry button java-me


    【解决方案1】:

    在您的按钮字段上调用 ​​invalidate() 应该会处理它。

    此外,您的 layout() 方法中仍然存在我在您之前的问题中指出的错误:Why does my rectangular bitmap get clipped to a square when I draw it?

    【讨论】:

    • 您好,感谢您的帮助。是的,我把事情搞砸了,不得不将我的源代码拉回早期版本。你也知道任何关于黑莓编程的好书吗?我是通过阅读 diff totriols 来学习的,它们并不能反映全局。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多