kenlistian

勤学多思

  IT博客 :: 首页 :: 新随笔 ::  :: 聚合  :: 管理 ::
  412 随笔 :: 0 文章 :: 23 评论 :: 0 Trackbacks
继续学习j2me的ui编程,下面是实现ticker的例子,运行就是这样子:




/*
一个简单的提示现实类,在每个窗体中只允许有一个该类的实例。
如下的例子。
其代码如同以前加载工程中一样,运行它,测试界面如下:

*/

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

public class tickerdemo1 extends MIDlet implements CommandListener {

    
private static final String TICKER_TEXT =
        
"类似走马灯,又类似提示器。。。 " + "运行下看看。。。" ;

    
private boolean firstTime;
    
private Form mainForm;
    
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
    
private Display myDisplay;
    
private Ticker t;

    
public tickerdemo1() {
        myDisplay 
= Display.getDisplay(this);
        firstTime 
= true;
        mainForm 
= new Form("新窗体");
        mainForm.setCommandListener(
this);
    }

    
protected void startApp() {
        
if (firstTime) {
            t 
= new Ticker(TICKER_TEXT);   //创建实例
            mainForm.setTicker(t);
            firstTime 
= false;
        }

        mainForm.addCommand(exitCommand);
        myDisplay.setCurrent(mainForm);
    }

    
protected void destroyApp(boolean unconditional) {
        myDisplay.setCurrent((Displayable)
null);
        notifyDestroyed();
    }

    
protected void pauseApp() {
    }

    
public void commandAction(Command c, Displayable s) {
        
if (c == exitCommand) {
            destroyApp(
true);
        }
    }
}

posted on 2008-06-22 12:00 kenlistian 阅读(858) 评论(0)  编辑 收藏 引用 所属分类: Java
只有注册用户登录后才能发表评论。