📄 parseurl.java~2~
字号:
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class ParseURL extends MIDlet implements CommandListener{
Display display;
Form result;
TextBox inputURL;
Command exitCmd;
Command parseCmd;
Command okCmd;
String defaultURL = "http://nokia.judaweb.com/pdf/MIDPProgrammingv0_9.pdf";
public ParseURL(){
display = Display.getDisplay(this);
inputURL = new TextBox("输入URL", defaultURL, 100, TextField.URL);
result = new Form("解析结果");
exitCmd = new Command("退出", Command.EXIT, 1);
parseCmd = new Command("解析", Command.SCREEN, 1);
okCmd = new Command("返回", Command.OK, 1);
inputURL.addCommand(exitCmd);
inputURL.addCommand(parseCmd);
inputURL.setCommandListener(this);
result.addCommand(okCmd);
result.setCommandListener(this);
}
public void startApp(){
display.setCurrent(inputURL);
}
public void pauseApp(){
}
public void destroyApp(boolean conditional){
}
public void commandAction(Command c, Displayable d){
if( c == exitCmd){
destroyApp(true);
notifyDestroyed();
}
else if (c == parseCmd){
try{
parse(inputURL.getString());
display.setCurrent(result);
}
catch(Exception ex){}
}
else if(c == okCmd){
display.setCurrent(inputURL);
}
}
void parse(String url) throws IOException{
HttpConnection con = (HttpConnection)Connector.open(url);
String protocol = "protocol:"+con.getProtocol();
result.append(protocol);
String host = "host:"+con.getHost();
result.append(host);
String port = "port:"+con.getPort();
result.append(port);
String fileName = "file:"+con.getFile();
result.append(fileName);
String query = "query:"+con.getQuery();
result.append(query);
String ref = "ref:"+con.getRef();
result.append(ref);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -