www.pudn.com > j2me_QQ.rar > ReceiveMessage.java


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; 
   } 
}