我已经创建了一个聊天客户端应用程序,但仍停留在登录对话框中。基本上,我希望注册按钮事件能够检测用户是否在字段框中输入了任何内容。该代码不起作用。



public class RegButtonListener implements ActionListener
{
	public void actionPerformed(ActionEvent event)
	{
		if(userBox.getText() != null)
		{
			System.out.println("Lol");
		}
	}
}

最佳答案

您可以通过两种方式检查它是否为空(在这种情况下为非空):
使用isEmpty()或equals("")

if (!userBox.getText().isEmpty()){
    //code
}


要么

if (!userBox.getText().equals("")){
    //code
}

07-24 09:46
查看更多