《J2ME图形应用基础》中的例子

源代码在线查看: tickerdemo.java

软件大小: 13 K
上传用户: nanbeilisa
关键词: J2ME 图形
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*
				 *  TickerTest.java
				 *
				 * Created on 2005年3月1日, 上午11:14
				 */
				
				import javax.microedition.lcdui.*;
				import javax.microedition.midlet.*;
				
				/**
				 * TickerTest demonstrates the ticker component
				 *
				 * @see MIDlet
				 */
				public class TickerDemo extends MIDlet implements CommandListener {
				    
				    //Display管理
				    Display display = null;
				    
				    //Form对象
				    Form form = new Form("这是窗口的标题");
				    //Ticker对象
				    Ticker ticker = new Ticker("这是滚动文字");
				    
				    //创建命令按钮
				    static final Command cmdAddTitle =
				            new Command("显示标题", Command.ITEM,1);
				    static final Command cmdRemoveTitle =
				            new Command("删除标题", Command.ITEM,1);
				    static final Command cmdAddTicker =
				            new Command("显示滚动条", Command.ITEM,1);
				    static final Command cmdRemoveTicker =
				            new Command("删除滚动条", Command.ITEM,1);
				    static final Command cmdAddStringLine =
				            new Command("添加一行滚动文字", Command.ITEM,1);
				    static final Command cmdGetTickerString =
				            new Command("获得滚动文字", Command.ITEM,1);
				    static final Command cmdExit = new Command("退出", Command.STOP, 2);
				    
				    int count = 1;
				    
				    public void startApp() throws MIDletStateChangeException {
				        //设置Displayable对象
				        form.addCommand(cmdExit);
				        form.addCommand(cmdAddTitle);
				        form.addCommand(cmdRemoveTitle);
				        form.addCommand(cmdAddTicker);
				        form.addCommand(cmdRemoveTicker);
				        form.addCommand(cmdAddStringLine);
				        form.addCommand(cmdGetTickerString);
				        form.setCommandListener(this);
				        
				        //显示滚动条
				        form.setTicker(ticker);
				        
				        display = Display.getDisplay(this); //获得当前MIDlet的Display对象
				        display.setCurrent(form);           //设置form对象为当前显示对象
				    }
				    
				    public void pauseApp() {
				    }
				    
				    public void destroyApp(boolean unconditional) {
				        notifyDestroyed();
				    }
				    
				    /**
				     * 处理命令按钮事件
				     */
				    public void commandAction(Command c, Displayable d) {
				        String label = c.getLabel();
				        if (label.equals("退出")) {
				            destroyApp(true);
				        } else if(label.equals("显示标题")) {
				            form.setTitle("显示标题");
				        } else if(label.equals("删除标题")) {
				            form.setTitle(null);
				        } else if(label.equals("显示滚动条")) {
				            form.setTicker(ticker);
				        } else if(label.equals("删除滚动条")) {
				            form.setTicker(null);
				        } else if(label.equals("添加一行滚动文字")) {
				            count++;
				            ticker.setString(ticker.getString() + "\n" + 
				                    "第" + count + "行滚动文字");
				        } else if(label.equals("获得滚动文字")) {
				            form.append("获得滚动文字:" + form.getTicker().getString());
				        }
				    }
				}
							

相关资源