-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise14_2.java
62 lines (54 loc) · 1.57 KB
/
Exercise14_2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Author: 王俊朗
Class: 软件工程1803
ID: 20181003043
*/
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.geometry.Insets;
import javafx.stage.*;
import javafx.scene.image.*;
public class Exercise14_2 extends Application
{
@Override
public void start(Stage primaryStage)
{
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(5, 15, 5, 15));
pane.setHgap(10);
pane.setVgap(10);
Image O = new Image("file:image/o.gif");
Image X = new Image("file:image/x.gif");
ImageView imageView1 = new ImageView(O);
ImageView imageView2 = new ImageView(X);
for (int i = 0; i < 3; i++) //这里的循环理论上没有问题,但找不到什么问题导致IDE一直报错
{
for (int j = 0; j < 3; j++)
{
int temp = (int)(Math.random() * 3);
if (temp == 0)
{
pane.add(new ImageView(X), j, i);
}
else if (temp == 1)
{
pane.add(new ImageView(O), j, i);
}
else
{
continue;
}
}
}
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise14_2");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}