IDE indicates that my if else statement is redundant and I need an explanation to why
<p>I am a beginner in programming. The Netbeans IDE is indicating that the following if-else statement is redundant:</p>

<pre><code>public boolean x = false;

private void add_labelMouseClicked(java.awt.event.MouseEvent evt) {                                       

    jPanel2.setVisible(x);
        if(x==false){
            x=true;
        }else
            x=false;
}         
</code></pre>

<p>And if I correct this if-else statement using the IDE it turns the code into this:     </p>

<pre><code>public boolean x = false;

private void add_labelMouseClicked(java.awt.event.MouseEvent evt) {                                       

    jPanel2.setVisible(x);
       x = x == false;
} 
</code></pre>

<p>I need a simple explanation on the second code and how come it has a similar function to the first code.</p>

<p>EDIT: I  really understand it now thanks to everyone who explained it in detail, I learned something new today thanks for all the replies everyone.
(I felt stupid afterwards lol)</p>