rss· 导航· 设为首页· 加入收藏
当前位置: 火魔网 » 程序开发 » 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();

    }

   }

在类上运行

顶一下
(0)
踩一下
(0)