【发布时间】:2014-01-18 15:38:57
【问题描述】:
package tic.tac.toe.menu;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class TicTacToeMenu extends Application {
@Override
public void start(Stage primaryStage) {
Button start = new Button();
start.setText("How to Play?");
start.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("\n"+"The goal of tic-tac-toe is to get 3 of your pieces in a row vertically, horizontally, or diagonally ");
System.out.println("To play this game click inside a square to put down your piece, you choose to be 'x' or 'o' at the start");
}
});
StackPane root = new StackPane();
root.getChildren().add(start);
Scene scene = new Scene(root, 350, 250);
primaryStage.setTitle("Tic-Tac-Toe");
primaryStage.setScene(scene);
primaryStage.show();}
public void exit(Stage primaryStage) {
Button exit = new Button();
exit.setText("Quit?");
exit.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
System.exit(0);
})} // this line I get the error
StackPane root=new StackPane();
root.getChildren().add(exit);
Scene scene = new Scene(root, 350, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
}
我是 Java 新手,我正在尝试制作菜单,但在第 40 行我收到一个错误,提示类型非法开始,我很困惑这意味着什么。我认为我的语法错误,但不确定要修复什么。
【问题讨论】:
-
老实说,SO 不是语法检查器。并使用一个 IDE,它会告诉你缺少括号/括号/等。
-
这是公共无效出口下的一个,我用评论标记了它
-
@BrianRoach 确定是的……看看下面的答案。效率也很高——众包是吗?
-
@bblincoe 我知道 ::sigh::
标签: java syntax menu compiler-errors javafx