我的J2ME编程联系(2)——DateField

- 中国WEB开发者网络 (http://www.webasp.net)
-- 技术教程 (http://www.webasp.net/article/)
--- 我的J2ME编程联系(2)——DateField (http://www.webasp.net/article/18/17648.htm)
-- 作者:未知
-- 发布日期: 2005-04-19
  
/*
 * dateFieldlet.java
 *
 * Created on 2005年4月15日, 上午11:32
 */
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
 *
 * @author  Administrator
 * @version
 */
public class dateFieldlet extends MIDlet implements CommandListener{
    
    private Form aForm;
    private Display aDisplay;
    private DateField aDateField;
    private Command exitCommand;
    private Command okCommand;
    private Alert anAlert;
    
    public dateFieldlet(){
        
        anAlert=new Alert("Today",null,null,AlertType.INFO);
        anAlert.setTimeout(3000);
                
        exitCommand=new Command("EXIT",Command.EXIT,1);
        okCommand=new Command("OK",Command.EXIT,1);
        
        aForm=new Form("DateFieldTest");
        aDateField=new DateField("Today’s date:",DateField.DATE_TIME);
        aForm.append(aDateField);
        
        aForm.addCommand(exitCommand);
        aForm.addCommand(okCommand);
        aForm.setCommandListener(this);
    }
    
    public void startApp() {
        aDisplay=Display.getDisplay(this);
        aDisplay.setCurrent(aForm);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void commandAction(Command c,Displayable d){
        //int i=0;
        String s="";
        
        if(c==exitCommand){
            destroyApp(false);
            notifyDestroyed();
        }
        
        else{
            s=aDateField.getDate().toString();
            anAlert.setString(s);
            aDisplay.setCurrent(anAlert,aForm);
            
        }
    }
}
    
    
    

webasp.net