2016-04-05 56 views
0

我試圖使3 JOptionPane。每個人都必須顯示一些數據。如何在單獨的JOptionPane中顯示不同的陣列

首先必須證明firstDataArray

的20信息只有在取消我希望新JOptionPane彈出它必須顯示secondDataArray等方面的信息,用戶點擊......

這個問題我「M面向是當用戶點擊取消在第一JOptionPane,第二JOptionPane正在顯示firstDataArray和secondDataArray(我想2分離JOptionPane具有不同陣列列表)

相同的所有信息時,取消第二個JOptionPane底部,第三個JoptionPane顯示3個數據的所有信息Array

我在做什麼錯?

十分讚賞,

低音

 String[] firstDataArray= new String[20]; 
      String[] secondDataArray= new String[20]; 
      String[] thirdDataArray= new String[20]; 

      firstDataArray= ClassA.getFirstData(); 
      secondDataArray= ClassA.getSecondData(); 
      thirdDataArray= ClassA.getThirdData(); 

      StringBuilder textRegion = new StringBuilder(); 

      String txt = JOptionPane.showInputDialog(null, 
        textRegion.append(Arrays.toString(firstDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choose Option)", 
        JOptionPane.PLAIN_MESSAGE); 
//If the user click cancel , show the other array in a new JoptionPane 
      if (txt == null) { 

       txt = JOptionPane.showInputDialog(null, 
         textRegion.append(Arrays.toString(secondDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choisir municipalite (Chose option)", 
         JOptionPane.PLAIN_MESSAGE); 


//If the user click cancel again , show the other array in a third JoptionPane 
        if (txt == null) { 

        txt = JOptionPane.showInputDialog(null, 
          textRegion.append(Arrays.toString(thirdDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Chose Option)", 
          JOptionPane.PLAIN_MESSAGE); 
        if (txt == null) { 

        } else { 
         setNomMunicipalite(txt); 
        } 

       } else { 
        setNomMunicipalite(txt); 
       } 
      } else { 
       setNomMunicipalite(txt); 
      } 

回答

2

你總是追加每個陣列相同的StringBuilder

使用一個新的每個JOptionPane

 StringBuilder textRegion = new StringBuilder(); 

     String txt = JOptionPane.showInputDialog(null, 
       textRegion.append(Arrays.toString(firstDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choose Option)", 
       JOptionPane.PLAIN_MESSAGE); 
     //If the user click cancel , show the other array in a new JoptionPane 
     if (txt == null) { 
      textRegion = new StringBuilder(); // <--- 
      txt = JOptionPane.showInputDialog(null, 
        textRegion.append(Arrays.toString(secondDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Choisir municipalite (Chose option)", 
        JOptionPane.PLAIN_MESSAGE); 


       //If the user click cancel again , show the other array in a third JoptionPane 
       if (txt == null) { 
       textRegion = new StringBuilder(); // <--- 

       txt = JOptionPane.showInputDialog(null, 
         textRegion.append(Arrays.toString(thirdDataArray).replace("[", "").replace("]", "").replace(",", "")).append('\n'), "Chose Option)", 
         JOptionPane.PLAIN_MESSAGE); 
       if (txt == null) { 

       } else { 
        setNomMunicipalite(txt); 
       } 

      } else { 
       setNomMunicipalite(txt); 
      } 
     } else { 
      setNomMunicipalite(txt); 
     } 
+0

天上,我怎麼錯過了.....是的,這是我的失誤謝謝! – napi15

+0

@ napi15很高興幫助。 :-) – RubioRic