?? midlet1.java
字號:
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);
conn.close() ;
in.close() ;
String message = buf.toString();
if(message.equals("YES"))
{
readyForInput = true;
message2.setString("ready");
}
else
{
String sendURL = "http://gamex.bbmf.net/test/chat/message.php";
conn = (HttpConnection)Connector.open(sendURL);
in = conn.openInputStream();
buf = new StringBuffer();
while ( (ch = in.read()) != -1)
buf.append( (char) ch);
conn.close() ;
in.close() ;
message = buf.toString();
System.out.print(message);
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/chat/message.php?msg=" + 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);
send.close() ;
in.close() ;
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 + -