在Blackberry Display上添加一个自动收报机

时间:2010-06-30 17:04:15

标签: blackberry footer ticker

我是黑莓新手,所以 请给黑莓代码添加黑莓显示底部的显示器?

仅需要如何创建代码。??

谢谢

1 个答案:

答案 0 :(得分:1)

试试这个

import java.util.Timer;
import java.util.TimerTask;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;

public class Ticker extends Field {

    String text;
    final int screenWidth = Display.getWidth();
    int offset = screenWidth;
    Timer timer = new Timer();
    final int delay = 30;

    public void setText(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }

    Ticker(String text) {
        this.text = text;
        final int width = Font.getDefault().getAdvance(text);
        TimerTask timerTask = new TimerTask() {
            public void run() {
                offset--;
                if (offset + width == 0) {
                    offset = screenWidth;
                }
                invalidate();
            }
        };
        timer.scheduleAtFixedRate(timerTask, delay, delay);
    }

    protected void layout(int width, int height) {
        int w = Display.getWidth();
        int h = Font.getDefault().getHeight();
        setExtent(w, h);

    }

    protected void paint(Graphics graphics) {
        graphics.drawText(text, offset, 0);
    }


}