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

J2ME環境配置

編輯:J2ME

特別提醒:在下載各個配置軟件時一定要注意版本兼容問題,否則將無法把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();

    }

   }

在類上運行

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