回答編集履歴
1
コードの間違いを修正
test
CHANGED
@@ -76,47 +76,53 @@
|
|
76
76
|
|
77
77
|
if (rb1.isSelected()) {
|
78
78
|
|
79
|
-
Thread thread = new Thread(
|
79
|
+
Thread thread = new Thread() {
|
80
80
|
|
81
|
-
|
81
|
+
@Override
|
82
82
|
|
83
|
-
|
83
|
+
public void run() {
|
84
84
|
|
85
|
-
|
85
|
+
Platform.runLater(() -> textArea.appendText("first\n"));
|
86
86
|
|
87
|
-
|
87
|
+
// for文をforEachに変更しています。Platform.runLaterで用いるlambda式から
|
88
88
|
|
89
|
-
|
89
|
+
// ループの制御変数iを参照するにはiがfinalでなくてはならず、forループが使いにくいからです
|
90
90
|
|
91
|
-
|
91
|
+
IntStream.range(0, 4).forEach(i -> {
|
92
92
|
|
93
|
-
|
93
|
+
try {
|
94
94
|
|
95
|
-
e
|
95
|
+
sleep(1000);
|
96
96
|
|
97
|
-
}
|
97
|
+
} catch (InterruptedException e) {
|
98
98
|
|
99
|
-
|
99
|
+
e.printStackTrace(); // デバッグ用
|
100
100
|
|
101
|
-
}
|
101
|
+
}
|
102
102
|
|
103
|
-
Platform.runLater(() -> textArea.appendText("l
|
103
|
+
Platform.runLater(() -> textArea.appendText("line" + i + "\n"));
|
104
104
|
|
105
|
-
|
105
|
+
});
|
106
106
|
|
107
|
-
tr
|
107
|
+
Platform.runLater(() -> textArea.appendText("last\n"));
|
108
108
|
|
109
|
-
|
109
|
+
Platform.runLater(() -> {
|
110
110
|
|
111
|
-
|
111
|
+
try {
|
112
112
|
|
113
|
-
|
113
|
+
join();
|
114
114
|
|
115
|
-
}
|
115
|
+
} catch (InterruptedException e) {
|
116
116
|
|
117
|
-
|
117
|
+
e.printStackTrace(); // デバッグ用
|
118
118
|
|
119
|
+
}
|
120
|
+
|
119
|
-
});
|
121
|
+
});
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
};
|
120
126
|
|
121
127
|
thread.start();
|
122
128
|
|