电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

在组件(components)之间共享Ticker


发布日期:2022/7/11
 

ticker在screen类中被定义为一个域(Field)它可以被连接到任何screen类的子集中在下面的例子中我们将展示如何将ticker连接到列表(List)和alert对象中

注意以下例子基于MIDP和CLDC

源代码

/*

* TickerExamplejava

**/

import javaxmicroeditionmidlet*;

import javaxmicroeditionlcdui*;

public class TickerExample extends MIDlet implements CommandListener

{

private Display display; // 对显示对象的引用Reference to Display object

private List lsProducts; // 主产品列表

private Alert alHelp;// 显现文字和图像的警告板

private Ticker tkSale; // 对现在销售的提示

private Command cmExit;// 退出命令

public TickerExample()

{

display = DisplaygetDisplay(this);

cmExit = new Command(Exit CommandSCREEN );

tkSale = new Ticker(Current Sale: Bobs Pretty Good Laptop only $);

lsProducts = new List(Products ChoiceIMPLICIT);

lsProductsappend(Laptop null);

lsProductsappend(Printer null);

lsProductsappend(Help null);

lsProductsaddCommand(cmExit);

lsProductssetCommandListener(this);

lsProductssetTicker(tkSale);

}

public void startApp()

{

displaysetCurrent(lsProducts);

}

public void pauseApp()

{ }

public void destroyApp(boolean unconditional)

{ }

public void showAlert()

{

try

{

// Create an image

Image im = ImagecreateImage(/helppng);

// Create Alert add text and image no sound

alHelp = new Alert(Help Information

Bobs Pretty Good Productsso much to choose from!

im null);

alHelpsetTimeout(AlertFOREVER);

alHelpsetTicker(tkSale);

}

catch(Exception e)

{

Systemoutprintln(Unable to read png image);

}

// Display the Alert Once dismissed return to product list

displaysetCurrent(alHelp lsProducts);

}

public void commandAction(Command c Displayable s)

{

if (c == ListSELECT_COMMAND)

{

switch (lsProductsgetSelectedIndex())

{

case :

Systemoutprintln(Laptop selected);

break;

case :

Systemoutprintln(Printer selected);

break;

case :

showAlert();

break;

}

}

else if (c == cmExit)

{

destroyApp(true);

notifyDestroyed();

}

}

}

上一篇:PDA操作系统大比拼之二

下一篇:鼠标右键的使用和启动弹出式菜单