receivemessage.java

来自「名称 移动QQ  一个手机上的QQ」· Java 代码 · 共 79 行

JAVA
79
字号
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ReceiveMessage extends Thread
{
   
   private String message="";
   private String ConnectionURL="";
   private StreamConnection con=null;
   private InputStream is=null;
   private int data=0;
   private List myList;
   private Display display;
   //private Command SendCommand;
   
   public ReceiveMessage(String ConnectionURL,Display d,List tb)
   {
      this.ConnectionURL=ConnectionURL;
      this.display=d;
      this.myList=tb;
      
      //SendCommand=new Command("发信息",Command.OK,1);
      //myTextBox.addCommand(SendCommand);
      //myTextBox.setCommandListener(this);
   }
   
   public void setConnectionURL(String ConnectionURL)
   {
      this.ConnectionURL=ConnectionURL;
   }
   
   public String getConnectionURL()
   {
      return ConnectionURL;
   }
   
   public void run()
   {
      String str="";
      while(true)
      {
        System.out.println("ok");
        try
        {
           con=(StreamConnection)Connector.open(ConnectionURL);
           is=con.openInputStream();
	   data=0;
	   try
	   {
	     StringBuffer sb=new StringBuffer();
	     while((data=is.read())!=-1)
	     {
	       sb.append((char)data);
	     }
	     message="";
	     message=sb.toString();
	     myList.append(message,loadImage("/face1.png"));
	     display.setCurrent(myList);
	     System.out.println(message);
	   }
	   catch(IOException e){ System.out.println("no"); }
	 }catch(IOException e){ System.out.println("nothing"); }
      }
   }
  public Image loadImage(String myImageURL)
   {
      Image myImage;
      try
      {
        myImage=Image.createImage(myImageURL);
      }
      catch(Exception e)
      {
        myImage=null;
      }
      return myImage;
   }
}

⌨️ 快捷键说明

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