熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

在組件(components)之間共享Ticker

2022-06-13   來源: JSP教程 

  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();
  }
  }
  }

From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19181.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.