moto388SDK http://kb.motorola.metrowerks.com/motorola/toolsHome.do jdk1.3.1 sun.com jcreator  http://www.jcreator.com/Download.htm 
1,怎么然程序知道是运行在模拟器上还是在手机上 看IMEI号。一般手机按"*#06#"就可得到imei码,每个手机是唯一的。 public void paint(Graphics g) {  g.drawString("Phone Parameter:",0, 0, 16|4);  g.drawString("IMEI:",0, 30,16|4);  g.drawString(System.getProperty("phone.imei"),0, 60,16|4);  g.drawString("Network Parameter:",0, 90, 16|4);  g.drawString("MCC:"+System.getProperty("phone.mcc"),0, 120,16|4);  g.drawString("MNC:"+System.getProperty("phone.mnc"),0, 150, 16|4);  g.drawString("LAI:"+System.getProperty("phone.lai"),0, 180, 16|4);  g.drawString("CID:"+System.getProperty("phone.cid"),0, 210, 16|4); } 
2 看别人的game源代码时,找不到resource(图片)的原因,   如果你还没有添加一个叫做J2ME_RESOURCE_DIR的新的环境变量的话,建立他,具体步骤如下: 
win98下:编辑c:\autoexec.bat文件,加入set J2ME_RESOURCE_DIR=你的工程目录,重起系统。 
win2k下:我的电脑-》属性-》高级-》环境变量-》系统-》添加-》名称:J2ME_RESOURCE_DIR 内容:你的工程目录 
配好后,每当你在jcreator中打开时,就自动转向你的J2ME_RESOURCE_DIR所指定的目录 
3 四级灰度的颜色值怎么表示? private final static int WHITE_COLOR = 0x00FFFFFF; private final static int LIGHT_GRAY = 0x00888888; private final static int DARK_GRAY = 0x00444444; private final static int BLACK_COLOR = 0x00000000; 
4 关于开发工具  MotoJ2SDK是为摩托罗拉388手机定制的命令行开发工具包,当然也可与IDE开发工具集成从而方便用户的开发。其中可以集成的开发环境包括:CodeWarrior, JCreator等。 
另外SUN公司还提供了Java的开发工具,J2ME Wireless Tookit是为无线手持设备(MDIP)定制的简易开发工具包。如果用户需要更强的IDE开发环境,那么请选用Forte for Java CE。目前SUN公司提供的开发工具中暂时还没有388的模拟器。 
Java 2 SDK 1.3是必备的,它提供开发、测试和运行Java程序的平台 
本人推荐jcreator. 
5 Jcreater+MotoJ2SDK的配置与使用心得 
假设安装路径如下: JCreator D:\Program Files\Xinox Software\JCreator LE motoj2sdk D:\Motoj2sdk 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 变为 -O -bootclasspath D:/motoj2sdk/lib $[JavaFiles] 
第三步  选择 Configure->Options->Tools 点击“New”选择 DOS command  名字为“Preverifier” 将 arguments 换为 d:\Motoj2sdk\bin\preverifier.exe -classpath "d:\Motoj2sdk\lib" -d . . 将 initial directory 变为 “$[PrjDir]” 
 第四步 
按上面的方法在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” 
第五步 
New DOS command “Create Jar” 
Change arguments to “"$[JavaHome]\bin\jar.exe" cvfM $[PrjName].jar META-INF\MANIFEST.MF *.CLASS *.png” 
Change initial directory to “$[PrjDir]” 
NOTE: You must add META-INF\MANIFEST.MF in the project 
NOTE: You must change the directory “com/mot/project/*.CLASS” when you create your project. 
NOTE:  If you have resource files, you should also add these files into jar file, 1 folder is not necessary.   
 ok!编辑工具配置完毕! 
新建一个工程——选择Empty Project 再取一个名字 比如:test 则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.*; 
 public class test extends MIDlet implements CommandListener { 
/** * The screen for this MIDlet */ private KeyEventsDemoCanvas myCanvas; 
/** * Reference to current Display */ private Display myDisplay; 
/** * Command to make sure soft key is not a key event */ private Command okCommand = new Command("OK", Command.OK, 1); 
test() { 
myDisplay = Display.getDisplay(this); myCanvas = new KeyEventsDemoCanvas(); myCanvas.addCommand(okCommand); myCanvas.setCommandListener(this); } 
/** * 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) { } 
/** * The screen for this application */ 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 */ g.setColor(FOREGROUND_COLOR); 
g.drawString("Press a key!", 0, 0, Graphics.TOP | Graphics.LEFT); 
if (lastKey != 0) { g.drawString("Key Code: " + lastKey, 0, g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT); try { 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); } 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); } } } 
6怎么在主类中响应按钮消息,这个对于切换显示很有帮助。 
//文件名 LWTDemoMIDlet.java import com.motorola.lwt.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; 
public class LWTDemoMIDlet extends MIDlet implements CommandListener { class ButtonScreen extends ComponentScreen { 
public ButtonScreen() { 
// Add a button to the screen Button b1 = new Button("b"); ///////////下面的代码是设定按钮高度 b1.setBottomEdge(Component.HEIGHT, 30); 
///////////下面的代码是设定按钮宽度 b1.setRightEdge(Component.WIDTH,80); 
///////////下面的代码是设定按钮y坐标,a相对屏幕最上 
b1.setTopEdge(Component.SCREEN_TOP, 10); 
///////////下面的代码是设定按钮x坐标相对前一个控件 b1.setLeftEdge(Component.PREVIOUS_COMPONENT_RIGHT, 30); 
 add(b1); 
  
// Add another button to the screen Button b2 = new Button("点我就行了"){ public void componentActuated() { Show(); } }; // Extend the right edge to the right edge of the screen b2.setRightEdge(Component.WIDTH, 220); b2.setBottomEdge(Component.HEIGHT, b2.getPreferredHeight() * 2); add(b2); Command next = new Command("Next", Command.OK, 1); Command prev = new Command("Previous", Command.BACK, 1); 
addCommand(next); addCommand(prev); } }; 
ButtonScreen screens = new ButtonScreen(); public LWTDemoMIDlet() { screens.setCommandListener(this); } protected void startApp() throws MIDletStateChangeException { Display.getDisplay(this).setCurrent(screens); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { } public void Show() { System.out.println("Get it on main Class"); 
 } public void commandAction (Command c, Displayable d)  { 
if (screens == d) { // Found it, check which command was triggered if (c.getCommandType() == Command.BACK) { System.out.println("back"); } else if (c.getCommandType() == Command.OK) { System.out.println("ok"); } return; } 
} 
} 
 7 中文显示,存储问题。把中文写入rms中,再读出。  public void openRMS(){   try{   recordStore = RecordStore.openRecordStore(RECORD_STORE,true);   }   catch(Exception e){db(e.toString());}   System.out.println("RMS opened successfully!");  } 
 public void closeRMS(){   try{   recordStore.closeRecordStore();   }   catch(Exception e){ db(e.toString());}   System.out.println("RMS closed successfully!");  } 
 public void deleteRMS(){   if(recordStore.listRecordStores() != null){   try{   recordStore.deleteRecordStore(RECORD_STORE);}   catch(Exception e){ db(e.toString());}   }   System.out.println("RMS deleted successfully!");  } 
 public void writeRMS(int id,String str ){  // String ws;  // userId = inputScreen.f1.getText();   System.out.println("check input: " +str);  // ws=new String(userId+"   "+score);   writeStream(id,str);   System.out.println("RMS writed successfully!");  }  public void writeStream(int id,String sData){   try{    ByteArrayOutputStream strmBytes = new ByteArrayOutputStream();    DataOutputStream strmDataType = new DataOutputStream(strmBytes);    byte[] record;       strmDataType.writeUTF(sData);    strmDataType.flush();    record = strmBytes.toByteArray();   if(recordStore.getNumRecords()==2)     recordStore.setRecord(id,record,0,record.length);   else   recordStore.addRecord(record,0,record.length); 
   strmBytes.reset();    strmBytes.close();    strmDataType.close();   }   catch(Exception e){ db(e.toString());} 
 } 
  public void readRMS(){   try{    byte[] data = new byte[50];    ByteArrayInputStream strmBytes = new ByteArrayInputStream(data);    DataInputStream strmDataType = new DataInputStream(strmBytes);   // for(int i=1;i <= recordStore.getNumRecords();i++){    // recordStore.getRecord(i,recData,0);    // System.out.println("read Record : " + i);         // topRecordScreen.ta1.appendText(i+" "+ strmDataType.readUTF()+"\n");                 System.out.println(recordStore.getNumRecords());   if(recordStore.getNumRecords()==2)   {      recordStore.getRecord(1, data, 0);         scr_chooseBus.f1.setText(strmDataType.readUTF());              System.out.println(strmDataType.readUTF());       strmBytes.reset();         recordStore.getRecord(2, data, 0);         scr_chooseBus.f2.setText(strmDataType.readUTF());        System.out.println(strmDataType.readUTF()); 
    strmBytes.reset();    }    strmBytes.close();    strmDataType.close();   }   catch(Exception e){ db(e.toString());}   System.out.println("RMS read successfully!");  }    private void db(String str){   System.err.println("RMS  error: " + str);  } 
  
   
 
  |