简体   繁体   English

堆栈问题,不存储值

[英]Stack issue, not storing values

I have written a browser for a side project, currently I have this code: 我已经为辅助项目编写了一个浏览器,目前我有以下代码:

ReadHTML is my constructor, and load web page is the method I use to load a web page, what should happen, is when the user presses back, it should trigger the action listener and then check if the stack has some content, however, I have tested this and found that the code will reach the action listener and the stack test will fail, leading me to believe that my program is not storing content into the stack, I would appreciate if someone could point out where I am going wrong, or a better way of doing this I would be most appreciative. ReadHTML是我的构造函数,而加载网页是我用于加载网页的方法,应该发生的情况是,当用户按下时,它应该触发动作侦听器,然后检查堆栈中是否包含某些内容,但是,我已经对此进行了测试,发现该代码将到达动作侦听器,并且堆栈测试将失败,这使我相信我的程序未将内容存储到堆栈中,如果有人可以指出我要去哪里,我将不胜感激,或者一个更好的方法,我将不胜感激。

If you don't have enough code, or need me to add more information, I can edit and post pretty quickly, thanks in advance! 如果您没有足够的代码,或者需要我添加更多信息,我可以很快地进行编辑和发布,谢谢。

Stack<String> backStack = new Stack<String>();
Stack<String> forwardStack = new Stack<String>();
boolean stackTest = false;

    private void loadWebPage(String userInput) {
    if (stackTest = true) {
        forwardStack.push(urlBox.getText());
        stackTest = false;
    } else {
        backStack.push(urlBox.getText());
    }
    try {
        webWindow.setPage(userInput);
        urlBox.setText(userInput);
    } catch (Exception e) {
        try {
            File file = new File(userInput);
            webWindow.setPage(file.toURI().toURL());
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
public ReadHTML() {
        forward.addActionListener(
    new ActionListener() {
        public void actionPerformed(ActionEvent forwardPress) {
            if (!forwardStack.empty()) {
                loadWebPage(forwardStack.pop());
            }
        }
    });
    back.addActionListener(
    new ActionListener() {
        public void actionPerformed(ActionEvent backPress) {
            if (!backStack.empty()) {
                stackTest = true;
                loadWebPage(backStack.pop());
            }
        }
    });
}

It looks like 看起来像

 if (stackTest = true) {

Should be 应该

 if (stackTest == true) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM