我不知道如何在joptionpane中打印出字符串和变量。可能吗?如果没有那么我该怎么办?
String peopleadded = JOptionPane.showInputDialog("How many people do you want to add");
int peopleadded1 = Integer.parseInt(peopleadded);
String[][] People = new String[peopleadded1][2];
System.out.println("put your name in the array");
People[0][0] = JOptionPane.showInputDialog("Put your Name");
System.out.println("put your password in the array");
People[0][1] = JOptionPane.showInputDialog("Put your Password");
PrintStream person = System.out.printf("Your array num [%s] and name is %s and your password is %s", 0, People[0][0], People[0][1]);
JOptionPane.showMessageDialog(null, person);
答案 0 :(得分:0)
使用"Text"+varName+"moretext"
等(没有printstream,直接在optionpane中)
编辑: 你可以用这个:
int peopleCount = Integer.parseInt(JOptionPane.showInputDialog(null,"How many people do you want to add?", "Add People", JOptionPane.QUESTION_MESSAGE));
String[][] addPeople = new String[peopleCount][2];
for (int i=0; i<peopleCount; i++) {
addPeople[i][0] = JOptionPane.showInputDialog(null,"Person "+(i+1)+"\'s name:","Person "+(i+1),JOptionPane.PLAIN_MESSAGE);
addPeople[i][1] = JOptionPane.showInputDialog(null,"Person "+(i+1)+"\'s password:","Person "+(i+1),JOptionPane.PLAIN_MESSAGE);
}
String people="";
for (int i=0; i<peopleCount; i++)
people+="Person "+(i+1)+":\n Name: "+addPeople[i][0]+"\n Password: "+addPeople[i][1]+"\n";
JOptionPane.showMessageDialog(null,people,"People added",JOptionPane.INFORMATION_MESSAGE);
或者,如果您想在单独的对话框中显示每个人:
int peopleCount = Integer.parseInt(JOptionPane.showInputDialog(null,"How many people do you want to add?", "Add People", JOptionPane.QUESTION_MESSAGE));
String[][] addPeople = new String[peopleCount][2];
for (int i=0; i<peopleCount; i++) {
addPeople[i][0] = JOptionPane.showInputDialog(null,"Person "+(i+1)+"\'s name:","Person "+(i+1),JOptionPane.PLAIN_MESSAGE);
addPeople[i][1] = JOptionPane.showInputDialog(null,"Person "+(i+1)+"\'s password:","Person "+(i+1),JOptionPane.PLAIN_MESSAGE);
}
for (int i=0; i<peopleCount; i++)
JOptionPane.showMessageDialog(null,"Person "+(i+1)+":\n Name: "+addPeople[i][0]+"\n Password: "+addPeople[i][1],"Person "+(i+1),JOptionPane.INFORMATION_MESSAGE);