views:

159

answers:

1

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;
    }
}

And 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.

+1  A: 

Try calling invalidate() in your setValue method.

Marc Novakowski
Its working Smoooth. I owe u big!! Thanks a lot
Bohemian