13,100
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Weather extends MIDlet implements CommandListener, Runnable {
private Display mDisplay;
private Command mExitCommand;
private Command mForecastCommand;
private Command mWeatherCommand;
private Image mImage1;
private Image mImage2;
private String mUrl1;
private String mUrl2;
mUrl1 = "http://www.weatherzone.com.au/wzservlet/wzwoys/button?postcode=2615&locality=FLOREY&type=0"; //weather image
mUrl2 = "http://www.weatherzone.com.au/wzservlet/wzwoys/button?postcode=2615&locality=FLOREY&type=1"; //forecast image
private Form mForm;
public Weather() {
mForm = new Form("Weather");
mImage1 = loadImage(mUrl1);
mImage2 = loadImage(mUrl2);
mExitCommand = new Command("Exit", Command.EXIT, 0);
mWeatherCommand = new Command("Weather", Command.SCREEN, 0);
mForecastCommand = new Command("Forecast", Command.SCREEN, 0);
mForm.addCommand(mExitCommand);
mFrom.addCommand(mWeatherCommand);
mForm.addCommand(mForecastCommand);
mForm.setCommandListener(this);
}
public void startApp() {
mDisplay = Display.getDisplay(this);
mForm.append(mImage1);
mForm.append(mImage2);
mDisplay.setCurrent(mForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c == mExitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (c == mWeatherCommand)
{
Alert mAlert = new Alert("Alert", "Weather clicked", mImage1, AlertType.INFO);
mAlert.setTimeout(2000);
mAlert.setImage(mImage1);
mDisplay.setCurrent(mAlert, mForm);
}
if (c == mForecastCommand) {
Alert mAlert = new Alert("Alert", "Forecast clicked", mImage2, AlertType.INFO);
mAlert.setTimeout(2000);
mAlert.setImage(mImage2);
mDisplay.setCurrent(mAlert, mForm);
}
}
public void run() {}
private Image loadImage(URL url) {
Image image = null;
try {
image = Image.createImage(url);
}
catch (IOException ioe) {
System.out.println(ioe);
}
return image;
}
}