Java &引用;“非法开始行动”;及;;“预期”;编译器错误
一行代码中有4个错误 “public action void actionPerformed(ActionEvent事件){”一行获得“非法开始操作”两次,预期获得“非法开始操作”两次 我从第一本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
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。我现在明白了。为什么我的问题被否决了两次?我做错了什么吗?感谢这些建议。我现在明白了。为什么我的问题被否决了两次?我做错了什么吗?