开发者

Blackberry - how to animate Custom Field?

I have created a custom field class "Seek" to draw a fillrectangle.

class Seek extends Field {
    int fill;
    protected void layout(int width, int height) {
        setExtent(320, 5);
    }
    protected void paint(Graphics graphics) {
        graphics.setColor(Color.RED);
        graphics.fillRect(0, 0, fill, 5);
    }
    protected void setValue(int value) {
        fill = value;
    }
}

开发者_如何学JAVAAnd I have created another class Test seek to set the fill value using a timer

public class TestSeek extends UiApplication {
    public static void main(String[] args) {
        TestSeek gbResults = new TestSeek();
        gbResults.enterEventDispatcher();
    }
    private TestSeek() {
        pushScreen(new ProgressScreen());
    }
}

class ProgressScreen extends MainScreen {
    Timer timer = new Timer();
    int i = 80;
    Seek SeekField = new Seek();

    public ProgressScreen() {
        add(SeekField);
        timer.schedule(new RemindTask(), 100, 10);
    }

    class RemindTask extends TimerTask {
        public void run() {
            if (i < 320) {
                i += 1;
                SeekField.setValue(i);
            } else
                timer.cancel();
        }
    }
}

But I am unable to animate filling the rectangle.


Try calling invalidate() in your setValue method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜