Domanda

How can you display multiple elements of an array in JOption pane without an individual window for each element? The following code will output a single window for each element of inputDie1[x], how can I list them? i.e. 5, 1, 6, 1, 2 in one window.

   for (int x = 0; x < 5; x++)
   {
       randomValue1 = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE 
          + LOWEST_DIE_VALUE);
                inputDie1[x].setValue1(randomValue1);

       randomValue2 = ((int)(Math.random() * 100) % HIGHEST_DIE_VALUE 
          + LOWEST_DIE_VALUE);
                inputDie2[x].setValue2(randomValue2);

       JOptionPane.showMessageDialog(null, inputDie1[x].getValue1());
   }

after concatenation

           for (int x = 0; x < 5; x++)
           {v1 = inputDie1[x].getValue1();}

           JOptionPane.showMessageDialog(null, v1);
È stato utile?

Soluzione

What you can do is rather than putting this JOptionPane.showMessageDialog(null, inputDie1[x].getValue1()); line in the loop, Make a string and concatenate every time in the loop and finally when you get out of the loop. Show this string in the JOptionPane Message Dialog

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top