package com.qfedu.utils;
/**
* 字符串工具类
*
* @author admin
*
*/
public class StringUtil {
/**
* 判断是否为空
*
* @param str
* @return
*/
public static boolean isEmpty(String str) {
if (str == null || "".equals(str.trim())) {
return true;
} else {
return false;
}
}
/**
* 判断是否不是空
*
* @param str
* @return
*/
public static boolean isNoEmpty(String str) {
if (str != null && "".equals(str.trim())) {
return true;
} else {
return false;
}
}
}
protected void LoginActionPerformed(ActionEvent e) {
String name =this.userNameTxt.getText();
String pwd = new String(this.PwdTxt.getPassword());
if(StringUtil.isEmpty(name)){//用户名为空
JOptionPane.showMessageDialog(null, "用户名不能为空");
}
if(StringUtil.isEmpty(pwd)){//用户名为空
JOptionPane.showMessageDialog(null, "密码不能为空");
}
效果: