Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.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 &引用;“非法开始行动”;及;;“预期”;编译器错误_Java - Fatal编程技术网

Java &引用;“非法开始行动”;及;;“预期”;编译器错误

Java &引用;“非法开始行动”;及;;“预期”;编译器错误,java,Java,一行代码中有4个错误 “public action void actionPerformed(ActionEvent事件){”一行获得“非法开始操作”两次,预期获得“非法开始操作”两次 我从第一本Java书中复制了这段代码,为什么它不编译 import javax.swing.*; import java.awt.event.*; public class SimpleGui1 implements ActionListener{ Jbutton button; public

一行代码中有4个错误

“public action void actionPerformed(ActionEvent事件){”一行获得“非法开始操作”两次,预期获得“非法开始操作”两次

我从第一本Java书中复制了这段代码,为什么它不编译

import javax.swing.*;
import java.awt.event.*;

public class SimpleGui1 implements ActionListener{
    Jbutton button;

    public static void main (String [] args) {
        SimpleGui1 gui = new SimpleGui1();
        gui.go();
    }

    public void go(){
        JFrame frame = new JFrame();
        button = new JButton("Click");

        button.addActionListener(this);

        frame.getContentPane().add(button);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 300);
        frame.setVisible(true);


        public void actionPerformed(ActionEvent event){
            button.setText("I've been clicked.");
        } //close actionPerformed
    } //close go()

}

无法在另一个方法内定义方法。请将
actionPerformed
移到
go
块外

 public void go(){
        JFrame frame = new JFrame();
        button = new JButton("Click");

        button.addActionListener(this);

        frame.getContentPane().add(button);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 300);
        frame.setVisible(true);


} //close go()



public void actionPerformed(ActionEvent event){
            button.setText("I've been clicked.");
} //close actionPerformed

无法在另一个方法内定义方法。请将
actionPerformed
移到
go
块外

 public void go(){
        JFrame frame = new JFrame();
        button = new JButton("Click");

        button.addActionListener(this);

        frame.getContentPane().add(button);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 300);
        frame.setVisible(true);


} //close go()



public void actionPerformed(ActionEvent event){
            button.setText("I've been clicked.");
} //close actionPerformed

在Java中(从1.7开始),嵌套方法无效。move ActionPerformed在goin Java之外(从1.7开始)嵌套方法无效。move ActionPerformed of the goThanks for the advice guys。我现在明白了。为什么我的问题被否决了两次?我做错了什么吗?感谢这些建议。我现在明白了。为什么我的问题被否决了两次?我做错了什么吗?