要求实现基本的visit,forward,backward,and quit 操作

解决方案 »

  1.   

    使用 javax.swing.JEditorPane 做浏览器的主窗口。
      

  2.   

    要考虑的是html的解析问题
    1.正则
    2.html parser
      

  3.   

    import java.io.*;
    public class demo {
    public static void main(String[] args)
    throws IOException {
    BufferedReader stdin = new BufferedReader(
    new InputStreamReader(System.in));
    String line = "";
    String current = "http://www.mainpage.com/";
    StringTokenizer st;
    String command;
    StackL fs = new StackL();// forward stack
    StackL bs = new StackL();// backward stack
    boolean ignored = false;
    while (true) {
    ignored = false;
    line = stdin.readLine();
    st = new StringTokenizer(line);
    command = (String) (st.nextToken());
    if(command.equals("QUIT")){
    break;
    }
    else if (command.equals("VISIT")) {
    bs.push(current);
    current = (String) (st.nextToken());
    fs.emptify();
    } else if (command.equals("FORWARD")) {
    if (fs.isempty()) {
    ignored = true;
    } else {
    bs.push(current);
    current = (String) fs.pop();
    }
    } else if (command.equals("BACK")) {
    if (bs.isempty()) {
    ignored = true;
    } else {
    fs.push(current);
    current = (String) bs.pop();
    }

    if(ignored)System.out.println("Ignored");
    else System.out.println(current);

    }
    // String url = (String) (st.nextToken());
    }
    }class StackL {
    private LinkedList list = new LinkedList(); public void push(Object v) {
    list.addFirst(v);
    } public Object top() {
    return list.getFirst();
    } public Object pop() {
    return list.removeFirst();
    } public void emptify() {
    list.clear();
    } public boolean isempty() {
    return list.isEmpty();
    }
    }以上是我写的实现基本操作,主要用文本方式在控制台模拟几个基本操作。不知道合不合适