【发布时间】:2015-04-05 03:40:50
【问题描述】:
我想在btnCurrentStatus 的点击事件上显示我的数组(标记),然后我想从用户那里返回选定的值。我使用的代码如下,但在这里通过showMessageDialog 方法我只能设法显示数组,我想要的是用户可以选择其中一个值,并且我想返回该索引。
如何实现?
btnCurrentStatus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int j = 0;
int c = 0;
for (int i = 0; i < total_question; i++) {
if (question_status[i] == 1) {
marked[j] = i + 1;
j++;
// System.out.println((i + 1) + " : Marked");
} else if (question_status[i] == 2) {
locked[k] = i + 1;
c++;
//System.out.println((i + 1) + " : Locked");
}
}
String display = "";
// String markedq []= new String[] {"1","2","3","4"};
for (int a = 0; a < marked.length; a++) {
if (marked[a] != 0) {
display += marked[a] + "\n";
}
}
JOptionPane.showMessageDialog(null, display);
}
});
【问题讨论】:
标签: java arrays swing joptionpane