sendmessage.java.bak

来自「类」· BAK 代码 · 共 92 行

BAK
92 行
字号
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.lcdui.*;

public class SendMessage 
{
   private String message="";
   private String ConnectionURL="";
   
   Alert alert;
   public SendMessage()
   {
     alert=new Alert("发送成功!");
     alert.setTimeout(Alert.FOREVER);
   }
   
   public void setMessage(String msg)
   {
     this.message=msg;
   }
   
   public String getMessage()
   {
     return message;
   }
   
   public void setConnectionURL(String str)
   {
     this.ConnectionURL=str;
   }
   
   public String getConnectionURL()
   {
     return ConnectionURL;
   }
   
   public void SendMsg()throws IOException
   {
       StreamConnection con=null;
       DataOutputStream os=null;
       StreamConnectionNotifier scn=(StreamConnectionNotifier)Connector.open(ConnectionURL);
       try
       {
         
         con=scn.acceptAndOpen();
         os=con.openDataOutputStream();
         String response=message;
	 message="";
	 os.writeUTF(response);
	 os.flush();
       }
       finally
       {
	 if(os!=null)
	 {
	    os.close();
	 }
	 if(con!=null)
	 {
	    con.close();
	 }
       } 
   }
}

void listen(String serverURL) throws IOException 
	{
	   StreamConnection con=null;
	   DataOutputStream os=null;
	   StreamConnectionNotifier scn=(StreamConnectionNotifier)Connector.open(serverURL);
	   try
	   {
	      con=scn.acceptAndOpen();
	      //display.setCurrent(alert,input);
	      os=con.openDataOutputStream();
	      String response=input.getString();
	      input.setString("");
	      os.writeUTF(response);
	      os.flush();
	   }
	   finally
	   {
	      if(os!=null)
	      {
	        os.close();
	      }
	      if(con!=null)
	      {
	         con.close();
	      }
	   } 
	}

⌨️ 快捷键说明

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