📄 midlet1.java~13~
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class MIDlet1 extends MIDlet implements CommandListener{
private static MIDlet1 instance;
private Form form;
private Command connect;
private Command send;
private Command exit;
private TextField message1;
private TextField message2;
private boolean readyForInput = false;
// private Displayable1 displayable = new Displayable1(this);
/** Constructor */
public MIDlet1() {
instance = this;
message1 = new TextField("Send","",50,TextField.ANY );
message2 = new TextField("Receive","",50,TextField.ANY );
exit = new Command("exit",Command.SCREEN ,1);
send = new Command("Send",Command.SCREEN ,1);
connect = new Command("Connect",Command.SCREEN ,1);
Item[] items = new Item[]{
message1,message2
};
form = new Form("Chat Form",items);
form.addCommand(connect);
form.addCommand(send);
form.addCommand(exit);
form.setCommandListener(this);
}
/** Main method */
public void startApp() {
Display.getDisplay(this).setCurrent(form);
}
/** Handle pausing the MIDlet */
public void pauseApp() {
}
/** Handle destroying the MIDlet */
public void destroyApp(boolean unconditional) {
}
/** Quit the MIDlet */
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
public void commandAction(Command c,Displayable d)
{
if(c == connect)
{
String connectURL = "http://gamex.bbmf.net/test/chat/connect.php" ;
try{
HttpConnection conn = (HttpConnection)Connector.open(connectURL);
InputStream in = conn.openInputStream();
int ch;
StringBuffer buf = new StringBuffer();
while((ch = in.read()) != -1)
buf.append((char)ch);
String message = buf.toString();
if(message.equals("YES"))
{
readyForInput = true;
message2.setString("ready");
}
else
{
String sendURL = "http://gamex.bbmf.net/test/message.php";
conn = (HttpConnection)Connector.open(sendURL);
in = conn.openInputStream();
buf = new StringBuffer();
while ( (ch = in.read()) != -1)
buf.append( (char) ch);
message = buf.toString();
message2.setString(message);
readyForInput = true;
}
}catch(Exception e)
{
System.out.print(e.getMessage() );
}
}
if(c == exit )
{
destroyApp(false);
notifyDestroyed();
}
if(c == send)
{
if(!readyForInput)
return;
// message1.setString("hello");
String sendURL = "http://gamex.bbmf.net/test/message.php?message=" + message1.getString() ;;
try{
HttpConnection send = (HttpConnection)Connector.open(sendURL);
InputStream in = send.openInputStream();
// InputStream in = conn.openInputStream();
int ch;
StringBuffer buf = new StringBuffer();
while((ch = in.read()) != -1)
buf.append((char)ch);
String message = buf.toString();
message2.setString(message);
readyForInput = false;
}catch(Exception e)
{
System.out.print(e.getMessage() );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -