【发布时间】:2014-01-11 06:01:22
【问题描述】:
在这里寻找有关我的代码的帮助。我正在尝试创建一个JOptionPane 输入对话框,它将接受用户的输入(选项 1 或选项 2)并根据第一个输入显示下一个菜单。 1 和 2 会有不同的结果。
我这样做对吗?
代码:
public class MyJavaApplication {
public static void main(String[] args) throws FileNotFoundException {
//1. Options
List<String> optionList = new ArrayList<String>(); **//Create an array to store user input**
optionList.add("1");
optionList.add("2");
Object[] options = optionList.toArray(); **//Store option into array**
Object value = JOptionPane.showInputDialog(null,
"Please select your encryption Algorithm:(1 or 2)\n 1. Data Encryption Standard(DES) \n 2. Advanced Encryption Standard(AES)",
null,
options,
options[0],
options[1]); **//JOption input dialog asking for either option one or 2**
int index = optionList.indexOf(value);
编辑:
if (value == 1) {
List<String> optionList2 = new ArrayList<String>();
optionList2.add("ECB");
optionList2.add("CBC");
Object[] options2 = optionList2.toArray();
int value2 = JOptionPane.showOptionDialog(null,
"Please select your mode of operation:\n 1. Cipher Block Chaining(CBC) \n 2. Electronic Codebook(ECB)",
"Select",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
optionList2.get(0));
String option2 = optionList2.get(value2);
}}
【问题讨论】:
标签: java swing joptionpane