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

📄 talksocket.java

📁 名称 移动QQ  一个手机上的QQ
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import java.io.*;
public class TalkSocket extends MIDlet implements CommandListener 
{
	private Display display;
	//private String ClientURL1=getAppProperty("MIDlet-ClientURL1");
	//private String ClientURL2=getAppProperty("MIDlet-ClientURL2");
	
	//GoodMan HelloMan  HalfLife  LuckMan
	
	// 5651    5652       5653     5654 
	
	private String ClientURL1="serversocket://:5654";
	private String ClientURL2="socket://192.168.0.183:5654";
	private String SendURL="";
	private String Msg_String="LuckMan";
	private String Msg_String2="";
	private String serverURL=getAppProperty("MIDlet-ServerURL");
	private Command exitCmd,okCmd,seeCmd,exitCmd2;
	private Command SendCommand,LoginCommand;
	private Form form,form1;
	private TextBox OutTextBox;
	private List myList,URLList,LisTemp1,LisTemp2;
	private ReceiveMessage receiveMessage;
	private LoginServer loginserver;
	private SendMessage sendMsg;
	private RequestMessage requestMessage;
	private Image myImage;
	private ImageItem myImageItem;
	private Loginout myLoginout;
	
	
	public TalkSocket()
	{
	  display=Display.getDisplay(this);
	  SendCommand=new Command("发信息",Command.OK,1);
	  LoginCommand=new Command("登录",Command.OK,1);
	  exitCmd=new Command("返回",Command.OK,1);
	  exitCmd2=new Command("退出",Command.OK,1);
	  okCmd=new Command("发送",Command.OK,1);
	  seeCmd=new Command("查看信息",Command.OK,1);
	  
	  form=new Form(Msg_String);
	  form1=new Form(Msg_String);
	  
	  try
          { 
            myImage=Image.createImage("/QQ7.png");
          }catch(Exception e){}  
	  myImageItem=new ImageItem("",myImage,ImageItem.LAYOUT_DEFAULT,"登录中...");
	  form.append(myImageItem);
	  
	  form.addCommand(LoginCommand);
	  form.setCommandListener(this);
	  
	  myList=new List(null,Choice.EXCLUSIVE);
	  URLList=new List(null,Choice.EXCLUSIVE);
	  myList.setTitle("-----开始接收-----");
	  myList.addCommand(SendCommand);
	  myList.addCommand(seeCmd);
	  myList.addCommand(exitCmd2);
	  myList.setCommandListener(this);
	          
	  OutTextBox=new TextBox("发消息","",100,TextField.ANY);
	  OutTextBox.addCommand(okCmd);
	  OutTextBox.addCommand(exitCmd);
	  OutTextBox.setCommandListener(this);
	  
	}
	
	public void startApp()
	{
	  display.setCurrent(form);
	 
	  
	  requestMessage=new RequestMessage(display,myList,URLList,Msg_String);
	  requestMessage.setServerURL(ClientURL1);
	  requestMessage.start();
	  
	  loginserver=new LoginServer(display,myList,URLList);
	  //receiveMessage=new ReceiveMessage(serverURL,display,myList);
	  //receiveMessage.start();
	  sendMsg=new SendMessage();
	  myLoginout=new Loginout();
	}
	
	public void pauseApp()
	{}
	
	public void destroyApp(boolean b)
	{}
	
	public void commandAction(Command cmd,Displayable dis)
	{
	  if(cmd==SendCommand)
	  {
	    LisTemp1=requestMessage.getList();
	    LisTemp2=requestMessage.getURLList();
	    String str=LisTemp1.getString(LisTemp1.getSelectedIndex());
	    System.out.println(str);
	    int qq=0;
	    String str1="",str2="",str3="";
	    for(int i=0;i<URLList.size();i++)
	    {
	      SendURL="";
	      str3=URLList.getString(i);
	      qq=URLList.getString(i).indexOf('^');
	      if(qq!=-1)
	      {
	        str1 = LisTemp2.getString(i).substring(0,qq);
	        str2 = LisTemp2.getString(i).substring(qq+1);
	        if(str1.equals(str))
	        {
	          SendURL=str2;
	          System.out.println(SendURL);
	          break;
	        }
	      }
            }
             
            Msg_String2=Msg_String+"!"+SendURL;
            display.setCurrent(OutTextBox);
	  }
	  else if(cmd==okCmd)
	  {
	    try
	    {
	       sendMsg.setMessage(OutTextBox.getString());
	       sendMsg.setConnectionURL(Msg_String2,serverURL);
	       OutTextBox.setString("");
	       sendMsg.SendMsg();
	    }
	    catch(Exception e){}
	  }
	  else if(cmd==LoginCommand)
	  {
	    try
	    {
		    
		     loginserver.setMessage(Msg_String);
		     loginserver.setClientURL2(ClientURL2);
		     loginserver.setServerURL(serverURL);
		     loginserver.LoginMsg();
	    }
	    catch(Exception e){}	    
	  }
	  else if(cmd==exitCmd) 
	  {
	    display.setCurrent(requestMessage.getList());
	  }
	   else if(cmd==seeCmd) 
	  {
	    
	    display.setCurrent(requestMessage.getTextBox());
	  }
	  
	  else if(cmd==exitCmd2) 
	  {
	    
	    myLoginout.setMessage(Msg_String);
	    myLoginout.setConnectionURL(serverURL);
	    try
	    {
	      myLoginout.LogoutMsg();
	      myList=null;
	      URLList=null;
	      notifyDestroyed();
	      destroyApp(true);
	    }
	    catch(Exception e){}  
	  }
	  
	}
}
/*
   finally
   {
     if(is!=null)
     {
       is.close();
     }
     if(con!=null)
     {
       con.close();
     }
   }
   
    if(cmd==SendCommand)
	  {
	    display.setCurrent(inTextBox);
	  }
	  else if(cmd==okCmd)
	  {
	    display.setCurrent(inTextBox);
	  }
	  else if(cmd==exitCmd)
	  {
	    display.setCurrent(inTextBox);
	  }  
   
   
**/

⌨️ 快捷键说明

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