if(txtValueUIT.getText()==null || txtValueDolar.getText()==null || txtValueUIT.equals("") || txtValueDolar.equals(""))
JOptionPane.showMessageDialog(null, "You have not entered both values", "Error", JOptionPane.ERROR_MESSAGE);
我尝试做的是在JTextFfields为空或空时显示错误消息。 我正在使用if并且它没有显示任何错误但是在测试它时它根本不会显示该消息应该是什么时候。
* 它似乎根本不执行任何操作,因为当那些JtextFields中缺少值时,该方法中的代码将不会被处理。 *
下面的代码是另一个组件的setText
,用作参数从JTextField
获取文本的字符串
顺便说一下:
if(e.getSource() == btnRefresh) //I added the button with an action listener
refreshValues(); //this contains the code with the JOptionPane
答案 0 :(得分:4)
尝试使用以下代码:
来自
txtValueUIT.equals("") || txtValueDolar.equals("")
要
txtValueUIT.getText().equals("") || txtValueDolar.getText().equals("")