⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mid.java~18~

📁 J2ME的一个简单例子
💻 JAVA~18~
字号:
package j2me;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.Connector;

public class Mid extends MIDlet {

  Form form;
  public Mid() {
    form=new Form("My Form");
    Image image=null;
    try {
      image =createImage("http://han:8080/a.gif");
    }
    catch (IOException ex) {
      form=new Form("ERROR");
    }

    String strList[]={"First","Second","Third"};
    Image[] imgList=new Image[]{image,image,image};

    List list=new List("My List",List.EXCLUSIVE,strList,imgList);

    form.append(image);
    Display.getDisplay(this).setCurrent(list);
  }

  public void startApp() {
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public void quitApp() {
    destroyApp(true);
    notifyDestroyed();
  }

  private Image createImage(String name) throws IOException {
       if (name.startsWith("/")) {
           // Load as a resource with Image.createImage
           return Image.createImage(name);
       } else if (name.startsWith("http:")) {
           // Load from a ContentConnection
           HttpConnection c = null;
           DataInputStream is = null;
           try {
               c = (HttpConnection)Connector.open(name);
               int status = c.getResponseCode();
               if (status != 200) {
                   throw new IOException("HTTP Response Code = " + status);
               }

               int len = (int)c.getLength();
               String type = c.getType();
               if (!type.equals("image/png")) {
                   throw new IOException("Expecting image, received " + type);
               }

               if (len > 0) {
                   is = c.openDataInputStream();
                   byte[] data = new byte[len];
                   is.readFully(data);
                   return Image.createImage(data, 0, len);
               } else {
                   throw new IOException("Content length is missing");
               }
           } finally {
               if (is != null)
                   is.close();
               if (c != null)
                   c.close();
           }
       } else {
           throw new IOException("Unsupported media");
       }
   }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -