- May 5, 2005
- 169
- 0
- 0
Hello,
I need a little help in java namely regarding the JTextField. Is there anyway to get the text from the field and compare it to another string? No matter what I do the result is always false. I even initialized the value of the JTextField to "", but when I compare it to a string that also equals "", the result is still false. Please see example:
import java.awt.event.*;
import javax.swing.*;
public class CListener implements ActionListener
{
private JTextField textField;
boolean dec = false;
boolean first = false;
private String op;
double num1, num2, result;
//Constructor
public CListener(JTextField t)
{
textField = t;
textField.setText("");
System.out.println(textField.equals(""));
op = "";
num1 = num2 = result = 0.0;
}
}
Output after I create new CListener:
C:\JAVAFI~2\Chapter13>java CListener
false
C:\JAVAFI~2\Chapter13>
Why isn't this value true if textField.getText() = ""? Please help.
I need a little help in java namely regarding the JTextField. Is there anyway to get the text from the field and compare it to another string? No matter what I do the result is always false. I even initialized the value of the JTextField to "", but when I compare it to a string that also equals "", the result is still false. Please see example:
import java.awt.event.*;
import javax.swing.*;
public class CListener implements ActionListener
{
private JTextField textField;
boolean dec = false;
boolean first = false;
private String op;
double num1, num2, result;
//Constructor
public CListener(JTextField t)
{
textField = t;
textField.setText("");
System.out.println(textField.equals(""));
op = "";
num1 = num2 = result = 0.0;
}
}
Output after I create new CListener:
C:\JAVAFI~2\Chapter13>java CListener
false
C:\JAVAFI~2\Chapter13>
Why isn't this value true if textField.getText() = ""? Please help.