当我运行程序时,系统会弹出一个对话框,要求输入操作者的名字。
当点击取消时,系统就关闭;当名字输入为空,系统会提示要求输入姓名才能操作,然后又返回到输入名字的界面。我创建了一个输入的对话框
String name= JOptionPane.showInputDialog(null,"What is your name?");但是请问要完成上面的功能,应该如何写程序?
能否用do while?
当点击取消时,系统就关闭;当名字输入为空,系统会提示要求输入姓名才能操作,然后又返回到输入名字的界面。我创建了一个输入的对话框
String name= JOptionPane.showInputDialog(null,"What is your name?");但是请问要完成上面的功能,应该如何写程序?
能否用do while?
public static void main(String[] args){
//prompt user to enter name
String name=JOptionPane.showInputDialog(null, "What is your name?");
while(name.length()==0){
name = JOptionPane.showInputDialog(null, "Your name is NULL!");
}
SeatClient c = new SeatClient(name);
}Exception in thread "main" java.lang.NullPointerException
at SeatClient.main(SeatClient.java:280)
SeatClient c = new SeatClient(name); // name 为 null;