質問するログイン新規登録

質問編集履歴

1

ソースコードの追加

2017/07/03 02:51

投稿

otftrough
otftrough

スコア477

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,104 @@
1
1
  for文で何回かJDialogを出して、ダイアログ内でユーザーにボタンを押したり操作させてから、ダイアログを閉じたらforに戻って次の処理をするというのをしたいです。
2
2
  現状、そのままforの中にJDialogを作っているので、JDialogとforが別スレッドで進行し、すべてのダイアログが同時に表示されてしまい、for文も一気に最後まで回ってしまいます。
3
- for文を、ダイアログが閉じられるまで処理を止める方法を教えてください。
3
+ for文を、ダイアログが閉じられるまで処理を止める方法を教えてください。
4
+
5
+ 参考になるかわかりませんがソースの一部を載せておきます。
6
+ ```java
7
+ else{ //実行ボタンを押されて実行する。
8
+
9
+ File[] fl = dir.listFiles();
10
+ String end = "<html>完了"; //完了ダイアログに表示する文字列
11
+ for(int p = 0; p < product.size(); p ++){
12
+
13
+ String str = "";
14
+ int hitCount = 0;
15
+ if(!productNumber[p].getText().equals("")){
16
+ for(int i = 0; i < fl.length; i ++){
17
+
18
+ if(fl[i].getName().indexOf(productNumber[p].getText()) >= 0 && extension(fl[i].getName())){
19
+
20
+ hitCount ++;
21
+ str += fl[i].getName() + ",";
22
+ }
23
+ }
24
+ if(hitCount > 5){ //画像が6つ以上見つかったら選択画面を出す(JDialog)
25
+
26
+ JDialog jd = new JDialog(this);
27
+ jd.setDefaultCloseOperation(HIDE_ON_CLOSE);
28
+ jd.setTitle("画像を選択");
29
+
30
+ JPanel pa = new JPanel(null);
31
+ JScrollPane sp = new JScrollPane(pa);
32
+ sp.setBounds(0, 0, 520, 400);
33
+ jd.add(sp);
34
+
35
+ JLabel label = new JLabel("適用する画像をクリックしてください。");
36
+ label.setBounds(0, 0, 500, 16);
37
+ pa.add(label);
38
+
39
+ JButton[] imgbtn = new JButton[hitCount];
40
+ String[] imgFiles = separation(str, ",");
41
+ int heightMax = 0;
42
+ int top = 0;
43
+ for(int i = 0; i < hitCount; i ++){
44
+
45
+ imgbtn[i] = new JButton();
46
+ imgbtn[i].setBorder(new LineBorder(Color.black, 1));
47
+ imgbtn[i].addActionListener(this);
48
+ imgbtn[i].setActionCommand("imgbtn");
49
+
50
+ ImageIcon ii = new ImageIcon(change(dirDrop.getText(), "\\", "/") + "/" + imgFiles[i]);
51
+ ii = new ImageIcon(reSize(ii.getImage(), 100, -1));
52
+
53
+ imgbtn[i].setIcon(ii);
54
+ imgbtn[i].setText(imgFiles[i]);
55
+ imgbtn[i].setVerticalTextPosition(JLabel.BOTTOM);
56
+
57
+ int x = 0;
58
+ if(i % 5 == 0) x = 400;
59
+ else if(i % 4 == 0) x = 300;
60
+ else if(i % 3 == 0) x = 200;
61
+ else if(i % 2 == 0) x = 100;
62
+
63
+ if(heightMax < ii.getIconHeight()) heightMax = ii.getIconHeight();
64
+ if(x == 0 && i > 0) top = heightMax;
65
+
66
+ imgbtn[i].setBounds(x, i / 5 * top, 100, ii.getIconHeight());
67
+ pa.add(imgbtn[i]);
68
+ }
69
+
70
+ jd.setVisible(true);
71
+ }
72
+ str = imageSet(product.get(p)) + str.substring(0, str.length() - 1) + lastCom(6 - comCount(str));
73
+ product.set(p, str);
74
+ }
75
+ }
76
+ try(PrintWriter out = new PrintWriter(new FileWriter(csv))){ //実行の最後にcsvファイルに出力。完了ダイアログを出す。
77
+
78
+ out.println("商品番号,商品名,説明,価格,在庫数,公開状態,表示順,種類名,種類在庫数,画像1,画像2,画像3,画像4,画像5");
79
+ for(int i = 0; i < product.size(); i ++){
80
+
81
+ out.println(product.get(i));
82
+ }
83
+ JDialog jd = new JDialog(this);
84
+ jd.setDefaultCloseOperation(HIDE_ON_CLOSE);
85
+ jd.setTitle("完了");
86
+ JLabel label = new JLabel(end + "</html>");
87
+ JScrollPane sp = new JScrollPane(label);
88
+ jd.add(sp);
89
+ jd.setBounds(width / 2 - 150, height / 2 - 75, 300, 150);
90
+ jd.setVisible(true);
91
+
92
+ disp();
93
+ } catch(IOException ex){
94
+
95
+ ex.printStackTrace();
96
+ JDialog jd = new JDialog(this);
97
+ jd.setDefaultCloseOperation(HIDE_ON_CLOSE);
98
+ jd.setTitle("エラー");
99
+ jd.add(new JLabel("書き込みに失敗しました。"));
100
+ jd.setBounds(width / 2 - 50, height / 2 - 40, 100, 80);
101
+ jd.setVisible(true);
102
+ }
103
+ }
104
+ ```