日期:2014-05-20  浏览次数:20799 次

J2ME 如何实现StringItem的内容在超过一定的长度实现其内容的滚动

我在项目中遇到如题的问题,其实讲起来很简单,但是当时面对我没有接触过的代码和上万行的代码,一看就无从下手,当时就想写个定时器类让在满足的条件下触发,后来想想其时没有那么多麻烦,写个线程使其在内容超过组建的长度时移动坐标。至于如何把它绘到标题栏上面的这里不说了,有空再整理。?

class MoveItemContentTask /*extends TimerTask*/? implements Runnable {
??????? // private Timer timer;
??????? private boolean ismoving;

??????? private int moveX, tempX;

??????? private int left, right;

??????? public MoveItemContentTask() {
??????????? /// = new Timer();
??????????? MoveItemContentTask beigin = new MoveItemContentTask();
??????????? new Thread(beigin).start();
??????? }

??????? public void movingPain(int x, int y, int leftBorder, int rightBorder, boolean isFocused, Graphics g) {
??????????? moveX = x;
??????????? tempX = x;
??????????? ismoving = isFocused;
??????????? left = leftBorder;
??????????? right = rightBorder;
??????????? //while (ismoving) {
??????????????? paintContent(moveX, y, leftBorder, rightBorder, g);
?????????? // }
??????? }

??????? public void run() {
??????????? // if (timer != null) {
??????????? changeX(moveX);
??????????? // }
??????????? try {
??????????????? Thread.sleep(50);
??????????? } catch (InterruptedException e) {
??????????????? e.printStackTrace();
??????????? }
??????? }

??????? public void changeX(int x) {
??????????? if (ismoving) {
??????????????? if (x < left || x > right) {
??????????????????? x = tempX;
??????????????? } else {
??????????????????? x += 1;
??????????????? }
??????????? }
??????? }

??? }