大家好,我正在编写一个交互式图形用户界面程序。基本上它接受下面的TextArea的所有输入和显示信息。但是如果它是空的或空的,它将验证所有的输入。 我的问题是,例如,名字是空的,它如何可以循环回到textField(名字字段)?并重新打字而不再继续?如何在Java中验证JTextField上的输入
我正在使用do while循环,但它只在使用JOptionPane窗口弹出时才起作用。让我澄清我的问题:我想要的是,当名字字段为空或空时,用户需要重新从文本字段而不是窗口重新打字,我不希望“JOPtionPane.showmessageDialog”窗口出来 谢谢
图像是这里
do{
whetherContinue=true;
FName=TxtFname.getText();
if(TxtFname.getText().isEmpty()){
FName = JOptionPane.showInputDialog("Please type your First Name");
TxtFname.setText(FName);
}
else{
}
if (FName==null)
System.exit(1);
try{
if (FName.isEmpty())
throw new ArithmeticException("First name can not be empty!");
whetherContinue = false;
}catch (Exception ex)
{
JOptionPane.showMessageDialog(null,"The first name can not be empty! Please type again");
}
}while(whetherContinue); //First Name while
你能澄清你的问题 ? –
我们希望您直接在这里发布您的代码和图像,以便轻松浏览。 –
此表格中的问题在此处不予回答,有关更多信息以阅读常见问题解答,特别是有关MCVE – mKorbel