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

📄 httpexample_3.java

📁 《精通JAVA手机游戏与应用程序设计》随书光盘
💻 JAVA
字号:

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

/*
 * 获得指定网页的数据
 */

public class HttpExample_3 extends MIDlet implements CommandListener {

	private Command exitCommand;

	private TextBox tb;

	String url = "http://127.0.0.1:8080/HelloWorld.html";

	public HttpExample_3() {
		exitCommand = new Command("Exit", Command.EXIT, 1);
		tb = new TextBox("显示服务器信息", "", 200, 0);
		tb.addCommand(exitCommand);
		tb.setCommandListener(this);
	}
	

	protected void startApp() {
		try {
			HttpConnection c = null;
			//InputStream s = null;
			StringBuffer b = new StringBuffer();
			try {
				long len = 0;
				int ch = 0;
				c = (HttpConnection) Connector.open(url);
				//显示服务器信息
				b.append("Host: "+ c.getHost()+"\n");
				b.append("Port: "+ c.getPort()+"\n");
				b.append("Date: "+ c.getDate()+"\n");
				b.append("Encoding: "+ c.getEncoding()+"\n");
				b.append("Protocol: "+ c.getProtocol()+"\n");
				b.append("File: "+ c.getFile()+"\n");
				b.append("Type: "+ c.getType()+"\n");
			} finally {
				//s.close();
				c.close();
			}

			tb.setString(b.toString());
			Display.getDisplay(this).setCurrent(tb);

		} catch (Exception e) {
			System.out.println("error");
			e.printStackTrace();

		}

	}

	protected void pauseApp() {
	}

	protected void destroyApp(boolean d) {

	}

	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {

			destroyApp(false);
			notifyDestroyed();
		}

	}

}

⌨️ 快捷键说明

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