我试图用javafx做一个tic tac toe游戏但突然添加了if
程序停止正常工作后如果[if(chiediConferma)
]我删除了所述错误,编译器在那里给我错误没有脚本中的任何错误。
现在让我解释一下程序如何首先通过一个确认框,程序会询问玩家他们是否想要玩tic tac toe然后如果玩家选择"si"
("yes"
in italian)他们的窗口随着游戏的出现,如果他们选择"no"
,程序就会结束。当我添加说如果游戏窗口显示为空白,当我点击它时,光标会转到加载图标,就像这样,直到出现"X stopped working"
弹出窗口,你对这是什么问题有所了解吗?
(对不起破解的语法和英语)
import java.util.Random;
import javafx.application.*;
import static javafx.application.Application.launch;
import javafx.event.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.geometry.*;
import javafx.collections.*;
public class ProgettoVisualeAngeloDenatalle4INF extends Application {
static int vittoriaOpareggio;
static int cVittoria;
static boolean chiediConferma;
static boolean conferma;
static boolean premuto00;
static boolean premuto01;
static boolean premuto02;
static boolean premuto10;
static boolean premuto11;
static boolean premuto12;
static boolean premuto20;
static boolean premuto21;
static boolean premuto22;
public static void main(String[] args) {
launch(args); // setta il programma come una javaFx Application
}
@Override
public void start(Stage window) throws Exception {
window.setTitle("Tris");
cVittoria = 0;
vittoriaOpareggio = 0;
chiediConferma = true;
premuto00 = true;
premuto01 = true;
premuto02 = true;
premuto10 = true;
premuto11 = true;
premuto12 = true;
premuto20 = true;
premuto21 = true;
premuto22 = true;
do {
if (chiediConferma) {
if (vittoriaOpareggio == 3) {
conferma = Menu.PartiMenu("Pareggio", "Vuoi giocare ancora?");
chiediConferma = false;
vittoriaOpareggio = 0;
} else if (vittoriaOpareggio == 1) {
conferma = Menu.PartiMenu("Vittoria", "Vuoi giocare ancora?");
chiediConferma = false;
vittoriaOpareggio = 0;
} else if (vittoriaOpareggio == 2) {
conferma = Menu.PartiMenu("Sconfitta", "Vuoi giocare ancora?");
chiediConferma = false;
vittoriaOpareggio = 0;
} else {
conferma = Menu.PartiMenu("", "Vuoi giocare a tris");
chiediConferma = false;
}
}
if (conferma) {
final int DIM = 3;
int matriceTris[][] = new int[DIM][DIM];
Button bott00 = new Button();
Button bott01 = new Button();
Button bott02 = new Button();
Button bott10 = new Button();
Button bott11 = new Button();
Button bott12 = new Button();
Button bott20 = new Button();
Button bott21 = new Button();
Button bott22 = new Button();
TextField text00 = new TextField("[ ]");
TextField text01 = new TextField("[ ]");
TextField text02 = new TextField("[ ]");
TextField text10 = new TextField("[ ]");
TextField text11 = new TextField("[ ]");
TextField text12 = new TextField("[ ]");
TextField text20 = new TextField("[ ]");
TextField text21 = new TextField("[ ]");
TextField text22 = new TextField("[ ]");
GridPane tabella = new GridPane();
tabella.setPadding(new Insets(10, 10, 10, 10));
tabella.setVgap(10);
tabella.setHgap(5);
tabella.setConstraints(text00, 0, 0);
tabella.setConstraints(text01, 0, 2);
tabella.setConstraints(text02, 0, 4);
tabella.setConstraints(text10, 1, 0);
tabella.setConstraints(text11, 1, 2);
tabella.setConstraints(text12, 1, 4);
tabella.setConstraints(text20, 2, 0);
tabella.setConstraints(text21, 2, 2);
tabella.setConstraints(text22, 2, 4);
tabella.setConstraints(bott00, 0, 1);
tabella.setConstraints(bott01, 0, 3);
tabella.setConstraints(bott02, 0, 5);
tabella.setConstraints(bott10, 1, 1);
tabella.setConstraints(bott11, 1, 3);
tabella.setConstraints(bott12, 1, 5);
tabella.setConstraints(bott20, 2, 1);
tabella.setConstraints(bott21, 2, 3);
tabella.setConstraints(bott22, 2, 5);
tabella.getChildren().addAll(text00, text01, text02, text10, text11, text12, text20, text21, text22, bott00, bott01, bott02, bott10, bott11, bott12, bott20, bott21, bott22);
if (premuto00) {
bott00.setOnAction(e -> {
text00.setText("[X]");
matriceTris[0][0] = 1;
premuto00 = false;
});
}
if (premuto01) {
bott01.setOnAction(e -> {
text01.setText("[X]");
matriceTris[0][1] = 1;
premuto01 = false;
});
}
if (premuto02) {
bott02.setOnAction(e -> {
text02.setText("[X]");
matriceTris[0][2] = 1;
premuto02 = false;
});
}
if (premuto10) {
bott10.setOnAction(e -> {
text10.setText("[X]");
matriceTris[1][0] = 1;
premuto10 = false;
});
}
if (premuto11) {
bott11.setOnAction(e -> {
text11.setText("[X]");
matriceTris[1][1] = 1;
premuto11 = false;
});
}
if (premuto12) {
bott00.setOnAction(e -> {
text12.setText("[X]");
matriceTris[1][2] = 1;
premuto12 = false;
});
}
if (premuto20) {
bott20.setOnAction(e -> {
text20.setText("[X]");
matriceTris[2][0] = 1;
premuto20 = false;
});
}
if (premuto21) {
bott00.setOnAction(e -> {
text21.setText("[X]");
matriceTris[2][1] = 1;
premuto00 = false;
});
}
if (premuto22) {
bott22.setOnAction(e -> {
text22.setText("[X]");
matriceTris[2][2] = 1;
premuto22 = false;
});
}
Scene scenaTris = new Scene(tabella, 1200, 800);
window.setScene(scenaTris);
window.show();
} else {
vittoriaOpareggio = 4;
}
} while (vittoriaOpareggio == 0);
}
public static int controlloVittoria(int mat[][]) {
return 0;
}
这是菜单类:
public class Menu
public static boolean PartiMenu(String titolo, String messaggio){
Stage menu = new Stage();
menu.initModality(Modality.APPLICATION_MODAL);
Label Messaggio = new Label();
Messaggio.setText(messaggio);
Button si = new Button("Si");
Button no = new Button("No");
si.setOnAction(e -> {
scelta = true;
menu.close();
});
no.setOnAction(e -> {
scelta = false;
menu.close();
});
GridPane selezione = new GridPane();
selezione.setPadding(new Insets(10,10,10,10));
selezione.setVgap(10);
selezione.setHgap(10);
selezione.setConstraints(Messaggio, 1,0);
selezione.setConstraints(si, 0,1);
selezione.setConstraints(no, 2,1);
selezione.getChildren().addAll(Messaggio, si, no);
Scene SceneMenu = new Scene(selezione, 1000, 600);
menu.setTitle(titolo);
menu.setScene(SceneMenu);
menu.showAndWait();
return scelta;
}
}
这是错误屏幕:
run:
Exception in Application constructor
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class progetto.visuale.angelo.denatalle.pkg4inf.ProgettoVisualeAngeloDenatalle4INF
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
... 1 more
Caused by: java.lang.RuntimeException: Uncompilable source code - illegal start of type
at progetto.visuale.angelo.denatalle.pkg4inf.ProgettoVisualeAngeloDenatalle4INF.<init>(ProgettoVisualeAngeloDenatalle4INF.java:244)
... 13 more
Exception running application progetto.visuale.angelo.denatalle.pkg4inf.ProgettoVisualeAngeloDenatalle4INF
C:\Users\Enzo\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)