Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么提交按钮不能在GUI上工作_Java_Swing - Fatal编程技术网

Java 为什么提交按钮不能在GUI上工作

Java 为什么提交按钮不能在GUI上工作,java,swing,Java,Swing,我创建了一个ActionListener和按钮,但按钮不起作用 动作监听器应该与提交按钮集成,请帮助 代码: 您的代码看起来很好。 输入打印语句,您可以看到它正在工作 btSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // here the click happend so you can check y

我创建了一个
ActionListener
和按钮,但按钮不起作用

动作监听器应该与提交按钮集成,请帮助

代码:

您的代码看起来很好。 输入打印语句,您可以看到它正在工作

btSubmit.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        // here the click happend so you can check your Textfield

        String userEntered = txtEnter.getText();
        System.out.println("User enterd: " + userEntered);

        if(userEntered.equalsIgnoreCase("yes"))
        {
            System.out.println("Entered Yes");
        }
    }
});

看起来它应该可以正常工作。调试器是你的朋友,是吗?“提交”按钮怎么知道该做什么?你有没有收到任何错误或例外?没有,我什么都没有,我只是想征求一些意见,你们认为这样做对吗?你们能建议我如何执行一个简单的文件或脚本来检查它吗?谢谢你们!很好!多谢各位
btSubmit.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        // here the click happend so you can check your Textfield

        String userEntered = txtEnter.getText();
        System.out.println("User enterd: " + userEntered);

        if(userEntered.equalsIgnoreCase("yes"))
        {
            System.out.println("Entered Yes");
        }
    }
});