我试图制作3 JOptionPane
。每个人都必须显示一些数据。
第一个必须显示firstDataArray的20个信息
只有当用户点击取消时我想要弹出新的JOptionPane
,它必须显示secondDataArray等的信息......
我面临的问题是当用户点击第一个JOptionPane
上的取消时,第二个JOptionPane
显示firstDataArray和secondDataArray的所有信息(我想要2个分开) JOptionPane
具有不同的数组列表)
当第二个JOptionPane
的取消底部相同时,第三个JoptionPane
显示3数据数组的所有信息
我做错了什么?
很多欣赏,
低音
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);
}
答案 0 :(得分: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);
}