185k views
4 votes
50 POINTS

I'm trying to write a code.
flip = 1 is a boolean and b1 is a button.
I'm trying to say

if (flip==1&&b1)
{
out.print("You Win");
}

But I get an error saying "bad operand types for binary operator "&&".
Does than mean I have to change b1 to boolean? Then how should I change a button to a boolean?

Thoughtful answer or report.

User Zakiya
by
6.6k points

1 Answer

6 votes

Answer:

Look Below

Step-by-step explanation:

Yes, you need to change b1 to a boolean value. A button cannot be directly used as a boolean value in Java. You can use the isSelected() method to check if the button is selected or not. Here's the modified code:

if (flip == 1 && b1.isSelected()) {

out.print("You Win");

}

This will check if flip is 1 and if the b1 button is selected, and print "You Win" if both conditions are true.

User Brian Riehman
by
7.4k points