如何在 JOption Pane 中显示数组的多个元素,而无需为每个元素提供单独的窗口?以下代码将为 inputDie1[x] 的每个元素输出一个窗口,我如何列出它们?即在一个窗口中显示 5、1、6、1、2。
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());
}
连接后
for (int x = 0; x < 5; x++)
{v1 = inputDie1[x].getValue1();}
JOptionPane.showMessageDialog(null, v1);
最佳答案
您可以做的不是将这个 JOptionPane.showMessageDialog(null, inputDie1[x].getValue1());
行放入循环中,而是创建一个字符串并每次在循环中连接最后当你脱离循环时。在 JOptionPane 消息对话框中显示此字符串
关于Java:JOptionpane 元素列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23451977/