特別提醒:在下載各個配置軟件時一定要注意版本兼容問題,否則將無法把Eclipseme導入Eclipse庫中,最終無法搭建J2ME虛擬平台!
1.下載jdk.16+Eclipse3.2.2+EclipseMe 1.7.9+sun_Java_wireless_toolkit-2_5_2-Windows.exe;
2 .安裝JDK,解壓Eclipse3.2.2,安裝插件EclipseMe 1.7.9,安裝sun_wtk;
3.打開Eclpise,點擊菜單window--->Perferences---->J2ME----->DeviceManament------>import------>wtk主目錄下的bin,點擊refresh即可;
4 .新建工程測試。Eclipse--->new Project ---->J2ME---->J2ME Midlet Suite ---->輸入工程名;
5.在工程上右鍵new J2ME Midlet ----->輸入類名;
import Java.io.*;
import Java.io.InputStream;
import Javax.microedition.io.Connector;
import Javax.microedition.io.HttpConnection;
import Javax.microedition.lcdui.Command;
import Javax.microedition.lcdui.CommandListener;
import Javax.microedition.lcdui.Display;
import Javax.microedition.lcdui.Displayable;
import Javax.microedition.lcdui.Form;
import Javax.microedition.lcdui.TextBox;
import Javax.microedition.lcdui.Ticker;
import Javax.microedition.midlet.MIDlet;
import Javax.microedition.midlet.MIDletStateChangeException;
public class HelloWorld extends MIDlet implements CommandListener{
private TextBox text=new TextBox("","Hello World",20,0);
private Display display=null;
private Command command=null;
private Command command1=null;
private Command command2=null;
private Command command3=null;
public HelloWorld() {
display=Display.getDisplay(this);
command=new Command("cancel","這是長命令1",Command.BACK,2);
command1=new Command("ok",Command.EXIT,1);
command2=new Command("start Tick","這是長命令1",Command.SCREEN,2);
command3=new Command("stop Tick",Command.SCREEN,1);
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
System.out.println("destrory");
protected void pauseApp() {
System.out.println("pause");
protected void startApp() throws MIDletStateChangeException {
Form t=new Form("Test");
t.addCommand(command);
t.addCommand(command1);
//t.addCommand(command2);
//t.addCommand(command3);
t.setCommandListener(this);
display.setCurrent(t);
public void commandAction(Command c, Displayable s) {
if(c.getCommandType()==7)
{
display.getCurrent().setTicker(new Ticker("運作中"));
display.getCurrent().removeCommand(command);
command=new Command("send",1,1);
display.getCurrent().addCommand(command);
}
if(c.getCommandType()==1)
{
display.getCurrent().setTitle("Test Form");
display.getCurrent().setTicker(null);
System.out.println(display.getCurrent().getWidth()+" "+display.getCurrent().getHeight());
}
if(c.getLabel().equals("send"))
{
//System.out.println("send");
new Thread(new MyHandle()).start();
}
class MyHandle implements Runnable
public void run() {
try {
HttpConnection conn=(HttpConnection)Connector.open("http://user.qzone.QQ.com/664118018/main");
if(conn.getResponseCode()==HttpConnection.HTTP_OK)
{
System.out.println("xx");
InputStream is=conn.openInputStream();
DataInputStream dis=new DataInputStream(is);
String line=null;
while((line=dis.readUTF())!=null)
{
System.out.println(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
在類上運行