所以我有一个java应用程序开发,我使用按钮操作(当按钮点击时),所谓的"退出",我收到此错误:
illegal start of expresson at line 21
以及代码:
package apptutorial;
import javax.swing.*;
import java.awt.event.*;
public class AppDev extends JFrame {
public static void main(String[] args) {
JFrame myFrame = new JFrame();
String myTitle = "Alpha Application";
JButton button = new JButton("Exit");
myFrame.setTitle(myTitle);
myFrame.setSize(400, 300);
myFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
myFrame.setVisible(true);
myFrame.add(button);
button.setSize(100,50);
button.setVisible(true);
private void buttonActionPerformed(ActionEvent evt) {
System.exit(0);
}
}
}
答案 0 :(得分:3)
Java不支持嵌套方法。从<asp:ScriptManager>
方法
buttonActionPerformed
答案 1 :(得分:1)
您需要将buttonActionPerformed
放在main
public class AppDev extends JFrame {
public static void main(String[] args) {
JFrame myFrame = new JFrame();
String myTitle = "Alpha Application";
JButton button = new JButton("Exit");
myFrame.setTitle(myTitle);
myFrame.setSize(400, 300);
myFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
myFrame.setVisible(true);
myFrame.add(button);
button.setSize(100,50);
button.setVisible(true);
}
private void buttonActionPerformed(ActionEvent evt) {
System.exit(0);
}
}