Add A ticker to Blackberry Display

随声附和 提交于 2019-12-11 15:58:15

问题


im new to blackberry,So Please give a blackberry code for adding ticker to blackberry display bottom part of the disply ??

Need Only for how to Create a Ticker.??

Thank you


回答1:


try this

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


}


来源:https://stackoverflow.com/questions/3151587/add-a-ticker-to-blackberry-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!