Java没有来自线程或其他类的响应

Java没有来自线程或其他类的响应,java,multithreading,class,user-interface,void,Java,Multithreading,Class,User Interface,Void,只是提醒一下,这个问题是从我之前的问题延伸而来的。我得到的答案很好,但我遇到了新问题;所以这是一个完全不同的问题 正如我之前所说,我正在制作一个CMD副本,用户在JTextField中输入一个命令,然后输出到一个JScrollPane/JTextPane 以下是用户按下键盘上的ENTER键时JTextField的代码 问题是,一旦您阅读了下面的代码,代码甚至没有到达access(命令)中的第一个调试行;无效的没有产生错误,同样,不知道发生了什么。再一次,如果我能把代码组织成不同的类,我会很高兴的

只是提醒一下,这个问题是从我之前的问题延伸而来的。我得到的答案很好,但我遇到了新问题;所以这是一个完全不同的问题

正如我之前所说,我正在制作一个CMD副本,用户在JTextField中输入一个命令,然后输出到一个JScrollPane/JTextPane

以下是用户按下键盘上的ENTER键时JTextField的代码

问题是,一旦您阅读了下面的代码,代码甚至没有到达access(命令)中的第一个调试行;无效的没有产生错误,同样,不知道发生了什么。再一次,如果我能把代码组织成不同的类,我会很高兴的。但由于此代码仅在实际代码(如DateTime.class的代码)位于主类中时才起作用;我不知道该怎么办

    public void inputFieldActionPerformed(java.awt.event.ActionEvent evt) {
        print(inputField.getText()); // prints whatever the user entered in textfield to pane
            inputField.setText(""); // sets textfield blank
            inputField.requestFocus(); // requests textfield's focus
        String[] temp = inputField.getText().split(" "); // splits whatever user entered
        LinkedList<String> command = new LinkedList<>(Arrays.asList(temp)); // adds the array above into a linkedlist because I prefer them
        access(command); // handles the command
    }
打印功能

public static void print(String s) {
        Color c = Color.WHITE;
        Style style = output.addStyle("Style", null);
        StyleConstants.setForeground(style, c);
        try{
            if(!s.startsWith(" ")) {
                s = " "+s;
            }
            if(!s.endsWith("\n")) {
                s = s + "\n";
            }
            document.insertString(document.getLength(), s, style);
        }catch(Exception e){e.printStackTrace();}
    }
还有什么请告诉我。

大多数问题,如“问题是,一旦您阅读了下面的代码,代码甚至没有到达access(命令)中的第一个调试行”,您提到的原因是代码流由于某种原因无法到达该点。
由于在inputFieldActionPerformed()中调用了access(),因此您应该在此处添加断点并检查函数是否已执行。

我自己的语法再一次把我搞糊涂了。。。监视

        print(inputField.getText());
            inputField.setText("");
            inputField.requestFocus();
        String[] temp = inputField.getText().split(" ");
        LinkedList<String> command = new LinkedList<>(Arrays.asList(temp));
        System.out.println("reaching access");
        access(command); // handles the command
        System.out.println("passed access");
在拆分文本字段中的任何内容之前,行重置为空白。因此,当我通过循环传递linkedlist命令时,它没有任何内容

通过移动两行代码修复

        print(inputField.getText());
        String[] temp = inputField.getText().split(" ");
        LinkedList<String> command = new LinkedList<>(Arrays.asList(temp));
        System.out.println("reaching access");
        access(command); // handles the command
        System.out.println("passed access");
            inputField.setText(""); // notice its at the end now
            inputField.requestFocus(); // notice its at the end now
print(inputField.getText());
字符串[]temp=inputField.getText().split(“”);
LinkedList命令=新建LinkedList(Arrays.asList(temp));
System.out.println(“到达访问”);
访问(命令);//处理命令
System.out.println(“通过访问”);
inputField.setText(“”;//注意它现在在末尾
inputField.requestFocus();//注意它现在在末尾

唉,我觉得自己很笨

我不是Java UI开发人员,但我怀疑问题在于您正在显示线程之外调用
print(…)
。您正试图从另一个线程中更新
文档,我怀疑您需要一些同步,或者需要使用一些UI构造。好的,这里有一个更新,代码到达if(command.get(0).equals(“dt”))行,但没有进入循环。有什么想法吗?我会使用一个调试器:好的,这里有一个更新,代码到达if(command.get(0).equals(“dt”))行,但不进入循环。有什么想法吗?那问题出在哪里?猜测该命令。get(0)中没有“dt”字符串?这就是我们格式化代码的原因。在Eclipse源代码菜单->格式中。它有时会做一些愚蠢的事情,但在其他方面,它是强烈推荐的——特别是当涉及多个开发人员时。如果需要,可以编辑格式,但也建议使用默认格式。
        print(inputField.getText());
            inputField.setText("");
            inputField.requestFocus();
        String[] temp = inputField.getText().split(" ");
        LinkedList<String> command = new LinkedList<>(Arrays.asList(temp));
        System.out.println("reaching access");
        access(command); // handles the command
        System.out.println("passed access");
inputField.setText("");
                inputField.requestFocus();
        print(inputField.getText());
        String[] temp = inputField.getText().split(" ");
        LinkedList<String> command = new LinkedList<>(Arrays.asList(temp));
        System.out.println("reaching access");
        access(command); // handles the command
        System.out.println("passed access");
            inputField.setText(""); // notice its at the end now
            inputField.requestFocus(); // notice its at the end now