程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> Jcreater+MotoJ2SDK的配置與使用心得

Jcreater+MotoJ2SDK的配置與使用心得

編輯:J2ME
假設安裝路徑如下:
JCreator D:\Program Files\Xinox Software\JCreator LE
motoj2sdk D:\Motoj2sdk
Java手機網[www.cnjm.Net]JDK D:\jdk1.3.1
注意:要先擊活模擬環境,運行D:\MotoJ2SDK\generic\scripts\runConstructor.bat
選擇手機型號,選擇語言,選擇normal, 再"創建"。
啟動Jcreater之後我的配置如下:
第一步 選擇 Configure->Options->JDK Profiles
注意:一定新建 profile and select “D:\jdk1.3.1”
將名字改為“J2ME 388”
Add classes path “D:\Motoj2sdk\lib”
Add documentation path “D:\Motoj2sdk\docs”
分別將後加的兩行移到最上方.
第二步 選擇 Configure->Options->JDK Tools
選擇ComplIEr
選中 and edit it.
將 parameters 變為 -classpath D:/motoj2sdk/lib $[JavaFiles]
第三步
選擇 Configure->Options->Tools
Java手機網[www.cnjm.Net]點擊“New”選擇 DOS command
名字為“PreverifIEr”
將 arguments 換為 d:\Motoj2sdk\bin\preverifIEr.exe -classpath "d:\Motoj2sdk\lib" -d . .
將 initial directory 變為 “$[PrjDir]”

第4步
按上面的方法在New一個 DOS command
名字:“Run Emulator”
將 arguments 換成 “java -Djava.library.path=d:/MotoJ2SDK/lib -classpath "d:/MotoJ2SDK/bin/Emulator.jar";"d:/MotoJ2SDK/ConfigTool.jar" com.mot.tools.J2ME.emulator.Emulator -classpath$[PrjDir];"d:/MotoJ2SDK/lib" -deviceFile d:/MotoJ2SDK/bin/resources/device.props Javax.microedition.midlet.AppManager $[CurClass] -JSA 1 1”
將 initial directory 換成 “d:\Motoj2sdk\bin”
ok!編輯工具配置完畢!
新建一個工程——選擇Empty Project
再取一個名字 比如:test
Java手機網[www.cnjm.Net]則jcreater自動在你的工作目錄中生成目錄test
再new一個file選擇Java File
寫好你的原代碼,保存 如:test.Java
在Project中 選add file
然後選中你剛才的test.Java
注意:不要有package ;
編譯——》tools中的PreverifIEr進行預先審核——》tools中的Run Emulator進行模擬
test.Java 的例子:功能是捕捉鍵盤輸入的ascII嗎。
import Javax.microedition.lcdui.*;
import Javax.microedition.midlet.*;
Java手機網[www.cnjm.Net]
public class test extends MIDlet implements CommandListener {;
/**
Java手機網[www.cnjm.Net]* The screen for this MIDlet
*/
private KeyEventsDemoCanvas myCanvas;
/**
* Reference to current Display
*/
private Display myDisplay;
Java手機網[www.cnjm.Net]/**
* Command to make sure soft key is not a key event
*/
Java手機網[www.cnjm.Net]private Command okCommand = new Command("OK", Command.OK, 1);
test() {;
myDisplay = Display.getDisplay(this);
myCanvas = new KeyEventsDemoCanvas();
myCanvas.addCommand(okCommand);
myCanvas.setCommandListener(this);
Java手機網[www.cnjm.Net]};
/**
* Do nothing if a command is fired
*/
public void commandAction(Command c, Displayable s) {;
};
/**
* Start the MIDlet
*/
protected void startApp() throws MIDletStateChangeException {;
myDisplay.setCurrent(myCanvas);
};
/**
* Pause the MIDlet
*/
protected void pauseApp() {;
};
/**
* Called by the framework before the application is unloaded
*/
protected void destroyApp(boolean unconditional) {;
};
/**
Java手機網[www.cnjm.Net]* The screen for this application
*/
Java手機網[www.cnjm.Net]class KeyEventsDemoCanvas extends Canvas {;
/**
* Background color (i.e. the color of the screen)
*/
public final int BACKGROUND_COLOR = 0xFFFFFF; // white
/**
* Foreground color (i.e. the color of the rectangles)
*/
public final int FOREGROUND_COLOR = 0x000000; // black
/**
* Last key that was pressed
*/
private int lastKey;
/**
* Paint the screen
*/
public void paint(Graphics g) {;
/*
* Clear the screen
*/
g.setColor(BACKGROUND_COLOR);
g.fillRect(0, 0, getWidth(), getHeight());
/*
* Paint the message
Java手機網[www.cnjm.Net]*/
g.setColor(FOREGROUND_COLOR);
g.drawString("Press a key!", 0, 0, Graphics.TOP | Graphics.LEFT);
Java手機網[www.cnjm.Net]if (lastKey != 0) {;
g.drawString("Key Code: " + lastKey, 0, g.getFont().getHeight(),
Graphics.TOP | Graphics.LEFT);
try {;
Java手機網[www.cnjm.Net]g.drawString("Action: " + getGameAction(lastKey), 0,
2 * g.getFont().getHeight(),
Graphics.TOP | Graphics.LEFT);
g.drawString("Key Name: " + getKeyName(lastKey), 0,
3 * g.getFont().getHeight(),
Graphics.TOP | Graphics.LEFT);
Java手機網[www.cnjm.Net]}; catch (Exception e) {;
// ignore since alphabet keys will throw this exception
};
};
};
/**
* Handle key press
*/
public void keyPressed(int keyCode) {;
lastKey = keyCode;
repaint();
};
/**
* Demonstrate keyRepeated events
*/
public void keyRepeated(int keyCode) {;
System.out.println("Key repeated " + keyCode);
};
};
};
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved