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

📄 exhttp.java

📁 一个采用J2ME的游戏程序,对游戏开发者很具有参考价值,适合用于二次开发
💻 JAVA
字号:
package exframework;

/**
 * <p>Title: ExFramework</p>
 *
 * <p>Description: lizhenpeng</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: LP&P</p>
 *
 * @author lipeng
 * @version 1.0
 */
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.lcdui.*;
public class ExHttp implements AllAction,Runnable
{
  HttpConnection conn;
  MainForm form;
  public ExHttp()
  {

  }

  public void allAction(MainForm form)
  {

    ExHttp http  = new ExHttp();
    http.form = form;
    Thread t = new Thread(http);
    t.start();

   // conn=(HttpConnection)Connector.open("http://www.sina.com.cn");
  // Set the request method and headers
  /*
  try
  {
    conn.setRequestMethod(HttpConnection.POST);
    conn.setRequestProperty("If-Modified-Since","31 Aug 2005 0:55:31 GMT");
    conn.setRequestProperty("User-Agent",
                            "Profile/MIDP-2.0 Configuration/CLDC-1.0");
    conn.setRequestProperty("Content-Language","en-US");
  }
  catch(Exception e)
  {
  }

    StringBuffer sb=new StringBuffer(60);
    sb.append("Configuration/");
    sb.append(System.getProperty("microedition.configuration"));
    String prof=System.getProperty("microedition.profiles");
    int i=0;
    int j=0;
    while((j=prof.indexOf(' ',i))!=-1)
    {
      sb.append(" Profile/");
      sb.append(prof.substring(i,j));
      i=j+i;
    }
    sb.append(" Profile/");
    sb.append(prof.substring(i));
*/
  //设置请求为POST
  /*
  //conn.setRequestMethod(HttpConnection.POST);
 // os=conn.openOutputStream();
//  os.write("hello".getBytes());
 // os.flush();
  //int status=conn.getResponseCode();//判断连接是否正常
  if(status==HttpConnection.HTTP_OK)
  {
    is = conn.openInputStream();//打开输入流
    int ch;
    StringBuffer buf = new StringBuffer(100000);

    while((ch=is.read())!=-1)
    {
      //处理数据
      buf.append((char)ch);
    }
    System.out.println(buf);
      }*/



  }
  public void run()
  {
    try
    {
      conn=(HttpConnection)Connector.open("http://localhost:8080/examples/images/bg.png");

      InputStream in = conn.openInputStream();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int oneByte;
      while((oneByte = in.read())!=-1)
      {
        baos.write(oneByte);
      }
      byte[] b = baos.toByteArray();
      Image image = Image.createImage(b,0,b.length);
      this.form.append(image);
      if(in!=null)
      {
        in.close();
      }
      if(conn!=null)
      {
        conn.close();
      }
    }
    catch(Exception e)
    {
      System.out.print(e);
    }
  }
}

⌨️ 快捷键说明

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