日期:2014-05-20  浏览次数:21253 次

怎么实现else判断结束返回上一个if语句???
 String username=JOptionPane.showInputDialog("请输入您的昵称:");      
         if(username!=null&&username.length()>0)
         {
             System.out.println(username);
             JOptionPane.showMessageDialog(a, "输入的昵称为:"+username);
         } 
         else
        {
            JOptionPane.showMessageDialog(null, "请重新输入您的昵称!");
            return ;
        }
当输入为空时,系统弹出对话框“请重新输入您的昵称!”,此时怎么能返回“请输入您的昵称:”对话框,并继续执行程序呢???
java else/if判断循环 else返回上一个if语句 else返回继续运行 java窗口

------解决方案--------------------

public class DialogTest {

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub

String username = JOptionPane.showInputDialog("请输入您的昵称:");
if (username != null && username.length() > 0) {
System.out.println(username);
JOptionPane.showMessageDialog(null, "输入的昵称为:" + username);
} else {
JOptionPane.showMessageDialog(null, "请重新输入您的昵称!");
while(username == null 
------解决方案--------------------
 username.length() <=0){
username = JOptionPane.showInputDialog("请输入您的昵称:");
}
System.out.println(username);
}
}

}


------解决方案--------------------
 while(username == null 
------解决方案--------------------
 username.length() <=0){
                username = JOptionPane.showInputDialog("请输入您的昵称:");
            }

这个肯定是一直在等待用户输入啊。

楼主给你提供个思路,你可以加一个标记,比如用户输入3次为空的时候,直接结束,你想想