CounterItemTest.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:

J2ME

开发平台:

Java

  1. import java.io.*;
  2. import java.util.*;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.midlet.*;
  5. // A simple MIDlet to test the custom counter
  6. // component.
  7. public class CounterItemTest extends MIDlet
  8.                  implements CommandListener {
  9.     private Display display;
  10.     public static final Command exitCommand =
  11.                          new Command( "Exit",
  12.                                       Command.EXIT, 1 ); 
  13.     public CounterItemTest(){
  14.     }
  15.     public void commandAction( Command c,
  16.                                Displayable d ){
  17.         if( c == exitCommand ){
  18.             exitMIDlet();
  19.         }
  20.     }
  21.     protected void destroyApp( boolean unconditional )
  22.                        throws MIDletStateChangeException {
  23.         exitMIDlet();
  24.     }
  25.     public void exitMIDlet(){
  26.         notifyDestroyed();
  27.     }
  28.     public Display getDisplay(){ return display; }
  29.     protected void initMIDlet(){
  30.         Form f = new Form( "用CounterItem实现定时器" );
  31.         f.addCommand( exitCommand );
  32.         f.setCommandListener( this );
  33.         CounterItem counter = new CounterItem();
  34.         counter.setLayout( Item.LAYOUT_CENTER |
  35.                       Item.LAYOUT_NEWLINE_BEFORE |
  36.                       Item.LAYOUT_NEWLINE_AFTER );
  37.         f.append( counter );
  38.         getDisplay().setCurrent( f );
  39.     }
  40.     protected void pauseApp(){
  41.     }
  42.     protected void startApp()
  43.                       throws MIDletStateChangeException {
  44.         if( display == null ){ 
  45.             display = Display.getDisplay( this );
  46.             initMIDlet();
  47.         }
  48.     }
  49. }