username = new JTextField(10); add(username);
password = new JTextField(10); add( password );
if(username.getText() = "_____" + password.getText() == "______" )
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
username = new JTextField(10); add(username);
password = new JTextField(10); add( password );
if(username.getText() = "_____" + password.getText() == "______" )
This is very vague to me. Could you post some guidance, as I don't really know what you want to do?
Also, I did notice that this is problematic...
if(username.getText() = "_____" + password.getText() == "______" )
What are you doing here? The statement...
username.getText() = "_____" + password.getText()
...will not work, as what you are doing here is telling Java to assign the value of "_____" + password.getText() to username.getText(), which is impossible. Methods do not work like that. Please, explain what you are trying to do, then I might be able to help better.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
There are several things that need to be changed:
For "and" meaning "this as well as that" we use && not +. (+ is either an arithmetic operator meaning "added to", or a string concatenation operator meaning "joined on to". It already has enough to do!)
= and == do totally different things. = assigns the value of the expression on the right hand side to the variable on the left hand side. ==, on the other hand means "is the same as". Except...
When you are comparing objects, don't use ==. Use equals() instead. (== actually compares references values for equality, while .equals() is a method that any class can override to report whether objects should be considered the same. Don't worry about this - just use equals() to test for equality.)
if(username.getText().equals("foo")) { // etc
-----
Refer to your textbooks etc for basic syntax. Or Oracle's Tutorial. If you can't understand a compiler message it pays to post both the code and the complete message. Generally these messages are very useful so it is worth finding out what they mean, rather than concentrating just on how to fix some specific problem.
copeg (January 9th, 2012)
You're welcome.