有没有办法使用连续的JOptionPane输入对话框提示用户连续的阵列输入存储?也许我不善于提问,所以请参考下面的例子......
titleInputs[x] = JOptionPane.showInputDialog(null, "Please enter a book title, or zzz to
quit:");
authorInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s
author's last name, or zzz to quit: ")
pageInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s page
count, or zzz to quit: ")
你能找到第一个titleInput,然后是另一个inputDialog请求作者,最后是pageCount吗?同时参考您要查询的选择的初始标题?
以下是期望的结果: 标题#1 请输入标题: 请输入" title' s"作者: 请输入" title' s"页数: 标题#2 请输入标题: 请输入" title' s"作者: 请输入" title' s"页数: ......继续收集所有5个标题......
答案 0 :(得分:2)
int x = 0;
string currTitle = "";
do
{
currTitle = JOptionPane.showInputDialog(null, "Please enter a book title, or zzz to quit:");
if(!currTitle.equals("zzz"))
{
titleInputs[x] = currTitle;
authorInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s author's last name: ");
pageInputs[x] = JOptionPane.showInputDialog(null, "Please enter " + titleInputs[x] + "'s page count: ");
x = x+1;
}
} while(!currTitle.equals("zzz")) //if you wanted, you could do: while(!currTitle.equals("zzz") && x < MAX_ARRAY_SIZE) ...obviously after declaring MAX_ARRAY_SIZE somewhere.