質問編集履歴

1

ソースコードの追加

2017/07/03 02:51

投稿

otftrough
otftrough

スコア476

test CHANGED
File without changes
test CHANGED
@@ -3,3 +3,205 @@
3
3
  現状、そのままforの中にJDialogを作っているので、JDialogとforが別スレッドで進行し、すべてのダイアログが同時に表示されてしまい、for文も一気に最後まで回ってしまいます。
4
4
 
5
5
  for文を、ダイアログが閉じられるまで処理を止める方法を教えてください。
6
+
7
+
8
+
9
+ 参考になるかわかりませんがソースの一部を載せておきます。
10
+
11
+ ```java
12
+
13
+ else{ //実行ボタンを押されて実行する。
14
+
15
+
16
+
17
+ File[] fl = dir.listFiles();
18
+
19
+ String end = "<html>完了"; //完了ダイアログに表示する文字列
20
+
21
+ for(int p = 0; p < product.size(); p ++){
22
+
23
+
24
+
25
+ String str = "";
26
+
27
+ int hitCount = 0;
28
+
29
+ if(!productNumber[p].getText().equals("")){
30
+
31
+ for(int i = 0; i < fl.length; i ++){
32
+
33
+
34
+
35
+ if(fl[i].getName().indexOf(productNumber[p].getText()) >= 0 && extension(fl[i].getName())){
36
+
37
+
38
+
39
+ hitCount ++;
40
+
41
+ str += fl[i].getName() + ",";
42
+
43
+ }
44
+
45
+ }
46
+
47
+ if(hitCount > 5){ //画像が6つ以上見つかったら選択画面を出す(JDialog)
48
+
49
+
50
+
51
+ JDialog jd = new JDialog(this);
52
+
53
+ jd.setDefaultCloseOperation(HIDE_ON_CLOSE);
54
+
55
+ jd.setTitle("画像を選択");
56
+
57
+
58
+
59
+ JPanel pa = new JPanel(null);
60
+
61
+ JScrollPane sp = new JScrollPane(pa);
62
+
63
+ sp.setBounds(0, 0, 520, 400);
64
+
65
+ jd.add(sp);
66
+
67
+
68
+
69
+ JLabel label = new JLabel("適用する画像をクリックしてください。");
70
+
71
+ label.setBounds(0, 0, 500, 16);
72
+
73
+ pa.add(label);
74
+
75
+
76
+
77
+ JButton[] imgbtn = new JButton[hitCount];
78
+
79
+ String[] imgFiles = separation(str, ",");
80
+
81
+ int heightMax = 0;
82
+
83
+ int top = 0;
84
+
85
+ for(int i = 0; i < hitCount; i ++){
86
+
87
+
88
+
89
+ imgbtn[i] = new JButton();
90
+
91
+ imgbtn[i].setBorder(new LineBorder(Color.black, 1));
92
+
93
+ imgbtn[i].addActionListener(this);
94
+
95
+ imgbtn[i].setActionCommand("imgbtn");
96
+
97
+
98
+
99
+ ImageIcon ii = new ImageIcon(change(dirDrop.getText(), "\\", "/") + "/" + imgFiles[i]);
100
+
101
+ ii = new ImageIcon(reSize(ii.getImage(), 100, -1));
102
+
103
+
104
+
105
+ imgbtn[i].setIcon(ii);
106
+
107
+ imgbtn[i].setText(imgFiles[i]);
108
+
109
+ imgbtn[i].setVerticalTextPosition(JLabel.BOTTOM);
110
+
111
+
112
+
113
+ int x = 0;
114
+
115
+ if(i % 5 == 0) x = 400;
116
+
117
+ else if(i % 4 == 0) x = 300;
118
+
119
+ else if(i % 3 == 0) x = 200;
120
+
121
+ else if(i % 2 == 0) x = 100;
122
+
123
+
124
+
125
+ if(heightMax < ii.getIconHeight()) heightMax = ii.getIconHeight();
126
+
127
+ if(x == 0 && i > 0) top = heightMax;
128
+
129
+
130
+
131
+ imgbtn[i].setBounds(x, i / 5 * top, 100, ii.getIconHeight());
132
+
133
+ pa.add(imgbtn[i]);
134
+
135
+ }
136
+
137
+
138
+
139
+ jd.setVisible(true);
140
+
141
+ }
142
+
143
+ str = imageSet(product.get(p)) + str.substring(0, str.length() - 1) + lastCom(6 - comCount(str));
144
+
145
+ product.set(p, str);
146
+
147
+ }
148
+
149
+ }
150
+
151
+ try(PrintWriter out = new PrintWriter(new FileWriter(csv))){ //実行の最後にcsvファイルに出力。完了ダイアログを出す。
152
+
153
+
154
+
155
+ out.println("商品番号,商品名,説明,価格,在庫数,公開状態,表示順,種類名,種類在庫数,画像1,画像2,画像3,画像4,画像5");
156
+
157
+ for(int i = 0; i < product.size(); i ++){
158
+
159
+
160
+
161
+ out.println(product.get(i));
162
+
163
+ }
164
+
165
+ JDialog jd = new JDialog(this);
166
+
167
+ jd.setDefaultCloseOperation(HIDE_ON_CLOSE);
168
+
169
+ jd.setTitle("完了");
170
+
171
+ JLabel label = new JLabel(end + "</html>");
172
+
173
+ JScrollPane sp = new JScrollPane(label);
174
+
175
+ jd.add(sp);
176
+
177
+ jd.setBounds(width / 2 - 150, height / 2 - 75, 300, 150);
178
+
179
+ jd.setVisible(true);
180
+
181
+
182
+
183
+ disp();
184
+
185
+ } catch(IOException ex){
186
+
187
+
188
+
189
+ ex.printStackTrace();
190
+
191
+ JDialog jd = new JDialog(this);
192
+
193
+ jd.setDefaultCloseOperation(HIDE_ON_CLOSE);
194
+
195
+ jd.setTitle("エラー");
196
+
197
+ jd.add(new JLabel("書き込みに失敗しました。"));
198
+
199
+ jd.setBounds(width / 2 - 50, height / 2 - 40, 100, 80);
200
+
201
+ jd.setVisible(true);
202
+
203
+ }
204
+
205
+ }
206
+
207
+ ```