2016-04-05 38 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