gpt4 book ai didi

java - 使用 try catch 验证输入

转载 作者:行者123 更新时间:2023-11-30 06:52:29 25 4
gpt4 key购买 nike

<分区>

如果用户没有输入指定的单词,我试图通过创建异常错误来验证 java 中的输入文本字段,即 admin

        String username;
int phone1;

@Override
public void widgetSelected(SelectionEvent e) {
try
{
phone1 = Integer.parseInt(phone.getText());
}
catch (Exception exe)
{
MessageDialog.openError(shell, "Error","Phone number has to be a number");
return;
}

try
{
username = namefield.getText();
if (username!= "admin") {
throw (new Exception());
}
}
catch (Exception exe)
{
MessageDialog.openError(shell, "Error","The username must be admin");
return;
}


labelresult.setText("The name entered is:"+ username );


labelresult2.setText("The phone entered is:"+ phone1 );

手机用的完美

用户名呢?我该怎么办?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com