www.pudn.com > j2me_QQ.rar > TalkSocket.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