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