回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
もう少し調べていただきたいのですが、前の回答に考慮漏れがあったので回答します。
|
1
|
+
もう少し調べていただきたいのですが、前の回答に考慮漏れがあったので回答します。
|
2
|
-
`FileChooser
|
2
|
+
`FileChooser`と同じく、`showDialog`してください。`File`が返ってきます。
|
3
|
-
|
3
|
+
|
4
|
-
画像のサイズ(高さ)がそろっていないと、残念なことになります。
|
4
|
+
画像のサイズ(高さ)がそろっていないと、残念なことになります。
|
5
|
-
|
5
|
+
|
6
|
-
```Java
|
6
|
+
```Java
|
7
|
-
class saiEventHandler implements EventHandler<ActionEvent> {
|
7
|
+
class saiEventHandler implements EventHandler<ActionEvent> {
|
8
|
-
public void handle(ActionEvent e) {
|
8
|
+
public void handle(ActionEvent e) {
|
9
|
-
List<String> exts = Arrays.asList(".bmp", ".gif", ".jpg", ".jpeg", ".png"); // 画像拡張子
|
9
|
+
List<String> exts = Arrays.asList(".bmp", ".gif", ".jpg", ".jpeg", ".png"); // 画像拡張子
|
10
|
-
|
10
|
+
|
11
|
-
DirectoryChooser directoryChooser = new DirectoryChooser();
|
11
|
+
DirectoryChooser directoryChooser = new DirectoryChooser();
|
12
|
-
File dir = directoryChooser.showDialog(null);
|
12
|
+
File dir = directoryChooser.showDialog(null);
|
13
|
-
if (dir == null) return; // キャンセル時
|
13
|
+
if (dir == null) return; // キャンセル時
|
14
|
-
|
14
|
+
|
15
|
-
// File dir = new File("image"); // 該当フォルダ
|
15
|
+
// File dir = new File("image"); // 該当フォルダ
|
16
|
-
File[] files = dir.listFiles(); // 該当フォルダのフォルダ・ファイルを列挙
|
16
|
+
File[] files = dir.listFiles(); // 該当フォルダのフォルダ・ファイルを列挙
|
17
|
-
|
17
|
+
|
18
|
-
List<File> images = new ArrayList<>(); // 画像ファイル
|
18
|
+
List<File> images = new ArrayList<>(); // 画像ファイル
|
19
|
-
for (File file : files) {
|
19
|
+
for (File file : files) {
|
20
|
-
if (file.isDirectory()) continue; // フォルダは無視
|
20
|
+
if (file.isDirectory()) continue; // フォルダは無視
|
21
|
-
|
21
|
+
|
22
|
-
String fileName = file.getName(); // 名前
|
22
|
+
String fileName = file.getName(); // 名前
|
23
|
-
int index = fileName.lastIndexOf(".");
|
23
|
+
int index = fileName.lastIndexOf(".");
|
24
|
-
if (index == -1) continue; // 拡張子がなければ無視
|
24
|
+
if (index == -1) continue; // 拡張子がなければ無視
|
25
|
-
|
25
|
+
|
26
|
-
String ext = fileName.substring(index); // ファイル拡張子(.込み)
|
26
|
+
String ext = fileName.substring(index); // ファイル拡張子(.込み)
|
27
|
-
if (exts.contains(ext)) images.add(file); // 拡張子が画像だったら追加
|
27
|
+
if (exts.contains(ext)) images.add(file); // 拡張子が画像だったら追加
|
28
|
-
}
|
28
|
+
}
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
|
31
|
-
Pagination pagination = new Pagination(images.size());
|
31
|
+
Pagination pagination = new Pagination(images.size());
|
32
|
-
pagination.setPageFactory(pageIndex -> new ImageView(new Image(images.get(pageIndex).toURI().toString())));
|
32
|
+
pagination.setPageFactory(pageIndex -> new ImageView(new Image(images.get(pageIndex).toURI().toString())));
|
33
|
-
|
33
|
+
|
34
|
-
Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), event -> {
|
34
|
+
Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), event -> {
|
35
|
-
int pos = (pagination.getCurrentPageIndex() + 1) % pagination.getPageCount();
|
35
|
+
int pos = (pagination.getCurrentPageIndex() + 1) % pagination.getPageCount();
|
36
|
-
pagination.setCurrentPageIndex(pos);
|
36
|
+
pagination.setCurrentPageIndex(pos);
|
37
|
-
}));
|
37
|
+
}));
|
38
|
-
fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
|
38
|
+
fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
|
39
|
-
fiveSecondsWonder.play();
|
39
|
+
fiveSecondsWonder.play();
|
40
|
-
|
40
|
+
|
41
|
-
Stage stage5 = new Stage();
|
41
|
+
Stage stage5 = new Stage();
|
42
|
-
// Paginationのコントローラ部分を隠す(セコいw ちゃんとやるならcssをあてる .pagination .pagination-control { visibility: hidden; })
|
42
|
+
// Paginationのコントローラ部分を隠す(セコいw ちゃんとやるならcssをあてる .pagination .pagination-control { visibility: hidden; })
|
43
|
-
stage5.setScene(new Scene(new VBox(pagination), 200, 100));
|
43
|
+
stage5.setScene(new Scene(new VBox(pagination), 200, 100));
|
44
|
-
stage5.show();
|
44
|
+
stage5.show();
|
45
|
-
}
|
45
|
+
}
|
46
|
-
}
|
46
|
+
}
|
47
47
|
```
|