用于CLDC的Midlet Timer J2ME Wireless工具包2.5.2_0.1

时间:2016-01-06 18:36:23

标签: java-me midlet

有人可以告诉我,我不能建造这段代码吗? Gauge有问题,但我不明白我需要改变什么或什么。

当我尝试Bulid时,它会显示错误。



Building "Alert01"
warning: [options] source value 1.3 is obsolete and will be removed in a future release
warning: [options] target value 1.3 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
C:\Users\Benita\j2mewtk\2.5.2\apps\Alert01\src\Alert01.java:112: error: cannot find symbol
        alert.setIndicator(gauge);
             ^
  symbol:   method setIndicator(Gauge)
  location: variable alert of type Alert
1 error
3 warnings
com.sun.kvem.ktools.ExecutionException
Build failed




建立此代码



package Alert01;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Date;
import javax.microedition.lcdui.Gauge;

public class Alert01 extends MIDlet{

  Alert01 theMidlet;
  Image image;
  int count = 0;
  long baseTime;

  public Alert01(){
    System.out.println("Construct MIDlet");
    theMidlet = this;
    baseTime = new Date().getTime()/1000;
  }//end constructor
  //----------------------------------------------------//

  public void startApp(){
    System.out.println("Create and display a TextBox");

    TextBox textBox = new TextBox("TextBox Title",
                                  "TextBox contents",
                                  50,//width
                                  TextField.ANY);

    //Make the TextBox the current Displayable object.
    Display.getDisplay(this).setCurrent(textBox);

    //Now create and schedule a TimerTask that will
    // display and sound an alert repeatedly. The Alert
    // first appears at two seconds and repeats every
    // three seconds.
    Timer myTimer = new Timer();
    myTimer.schedule(new MyTimerTask(),2000,3000);

    //Sleep for 20 seconds.
    try{Thread.currentThread().sleep(20000);
    } catch(Exception e){}

    //Cancel the timer.
    myTimer.cancel();

    //Enter the destroyed state.
    this.destroyApp(true);
  }//end startApp

  public void pauseApp(){
  }//end pauseApp

  public void destroyApp(boolean unconditional){
    System.out.println("Destroy MIDlet");
    notifyDestroyed();
  }//end destroyApp
  //----------------------------------------------------//

  //This is a member class
  class MyTimerTask extends TimerTask{
    long time;

    public void run(){
      System.out.println("Display an Alert");

      try{
        //Select among two image files on the basis of
        // whether the current time in seconds is odd
        // or even.
        time = new Date().getTime()/1000 - baseTime;

        //Note that the following file names are case
        // sensitive.
        if((time % 2) == 0){//Even value
          image = Image.createImage(
                                  "/Alert01/redball.PNG");
        }else{//Odd value
          image = Image.createImage(
                                 "/Alert01/blueball.PNG");
        }//end else


        //Create an Alert object of type ALARM. This
        // results in an audible alarm that sounds like a
        // telephone ringing.
        Alert alert = new Alert("Alert Title",
                                "",
                                image,
                                AlertType.ALARM);

        //Cause the alert to display the time in seconds.
        alert.setString("Time in seconds:" + time);

        //Cause the alert to be visible for two seconds.
        alert.setTimeout(2000);

        //Create a Gauge that shows six bars.
        Gauge gauge = new Gauge(null,false,6,0);

        //Set the number of Gauge bars to be illuminated.
        gauge.setValue(++count);

        //Attach the Gauge to the alert.
        alert.setIndicator(gauge);

        //Make the Alert the current Displayable object.
        Display.getDisplay(theMidlet).setCurrent(alert);
      }catch(Exception e){
        e.printStackTrace();
      }//end catch
    }//end run
  }//end class MyTimerTask
  //====================================================//
}//end class Alert01
//======================================================//




1 个答案:

答案 0 :(得分:0)

MIDP 2.0上提供了setIndicator方法。您可能正在使用MIDP 1.0进行编译。