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.

So, if the string fp.forma is set to be "oval" (to draw an oval), at the printlns of this part of code, if get :

forma: oval
i entered here
false

So, the strange thing that fp.forma = oval, and the if should run if fp.forma == "pencil"!! As in the println System.out.println((fp.forma == "pencil")); that satement is false !!! Why does this if start if the statement is false ? I tried to replace == with equals. and i get the same thing !! Why ? This if is inside the public void mousePressed(MouseEvent e){}, and because this if runs even if i try to draw an oval, it makes that my program not to work properly !!

Re: Why does it enter this if ?

You should use the equals() method for comparing Strings.

If you think the computer isn't doing what you want or expect your code to do, look again at your code.
The computer is pretty reliable. It must be your code that is wrong.
Remember that ; are used to end statements. Does the if statement go beyond the ; at the end of the line?