程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> J2ME HELLOWORLD 小試牛刀

J2ME HELLOWORLD 小試牛刀

編輯:J2ME
T628降價了,買了一個玩玩,這個“雞雞”支持Java擴展,所以第一時間去http://developer.sonyeriCSSon.com/site/global/home/p_home.JSP下載了最新的SDK(FILE SIZE:42M),下載的時候要注意,SDK說明中應該指出支持T628,eclipse和eclipseme是早就下好的,下面就該安裝了:

1、安裝J2SE 1.4.2,並配置path和classpath
2、安裝semc_J2ME_sdk_2_1_5.exe,裝完後我沒有做任何配置(包括環境變量配置)
3、解壓縮eclipse,然後把eclipseme解壓縮到eclipse的plugins目錄中
4、然後就配置eclipseme(如圖1)
5、創建一個jeme工程,File/New/Project.../J2ME/J2ME Midlet Suite
6、在工程中添加Midlet,File/New/Other../J2ME/J2ME Midlet
7、編寫代碼
8、在Navigator的工程上點右鍵,執行右鍵菜單裡的J2ME/Create Package
9、用模擬器(圖2)或通過藍牙傳到手機上執行

(圖1)

(圖2)


代碼如下:
----------------------------------------------------------
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.StringItem;
import Javax.microedition.midlet.MIDlet;
import Javax.microedition.midlet.MIDletStateChangeException;
/*
* Created on 2005-1-10
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author libo
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Helloworld extends MIDlet implements CommandListener{
private Display display;
private Form mainForm;
private StringItem stringItem;
private Command exitCommand=new Command("Exit",Command.EXIT ,1);
/**
*
*/
public Helloworld() {
super();
// TODO Auto-generated constructor stub
}

/* (non-Javadoc)
* @see Javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
initMIDlet();
display.setCurrent(mainForm);
}

private void initMIDlet(){
String text;
display=Display.getDisplay(this);
mainForm=new Form("關於");
stringItem=new StringItem(null,null);
text="這是我的第一個J2ME程序!";
stringItem.setText(text);
mainForm.append(stringItem);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
}

/* (non-Javadoc)
* @see Javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see Javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
System.out.println("exit the application");
}

public void commandAction(Command cmd,Displayable display){
if(cmd==exitCommand)
{
try{
destroyApp(false);
notifyDestroyed();
}catch(MIDletStateChangeException e){
e.printStackTrace();
}
}
}

}


-----------------------------------------
代碼結束


提示:T628僅支持CLDC 1.0 和MIDP 1.0 ,在新建設工程時,平台選擇Sony Ericsson J2ME SDK(WTK 1.0.4) Platform ,如果選擇Sony EriCSSon J2ME SDK(WTK 2.1) Platform 則,在模擬器上可以運行,但傳到T628上會提示無效的應用程序。



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved