Add A ticker to Blackberry Display
im new to blackberry,So Please give a blackberry code for adding开发者_如何学Python ticker to blackberry display bottom part of the disply ??
Need Only for how to Create a Ticker.??
Thank you
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);
}
}
精彩评论