import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import javax.microedition.midlet.*; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import javax.microedition.lcdui.*; public class C0 extends MIDlet implements CommandListener, Runnable { Display disp; Form f; Command cmdConn; public C0() { super(); // TODO Auto-generated constructor stub disp=Display.getDisplay(this); f= new Form("Connect to web"); cmdConn =new Command("Connect",Command.OK,1); f.addCommand(cmdConn); f.setCommandListener(this); } protected void startApp() throws MIDletStateChangeException { // TODO Auto-generated method stub disp.setCurrent(f); } protected void pauseApp() { // TODO Auto-generated method stub } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub } public void commandAction(Command arg0, Displayable arg1) { // TODO Auto-generated method stub if (arg0 == cmdConn) { Thread t =new Thread(this); t.start(); } else {this.notifyDestroyed();} } public void run() { // TODO Auto-generated method stub HttpConnection conn; try { conn = (HttpConnection)Connector.open("http://ycc.tsu.edu.tw/"); if(conn.getResponseCode()==HttpConnection.HTTP_OK) { DataInputStream dis = new DataInputStream(conn.openInputStream());//大水管 InputStreamReader isr= new InputStreamReader(dis,"BIG5");//小水管 StringBuffer sb = new StringBuffer();//水桶 int c = 0; while((c=isr.read())!=-1) { sb.append((char)c); } f.append(sb.toString()); } else { f.append("Failed!"); } } catch (IOException e) { e.printStackTrace(); } } }