If $A$ and $B$ are nonempty sets, prove that $A \times B = B \times A$ if and only if $A = B$ 
If $A$ and $B$ are nonempty sets, prove that $A \times B = B \times A$ if and only if $A = B$.

Proving the first direction of this is easy. That is, if $A = B$ then it is obvious that $A^2 = A^2$. I am wondering how to prove the other direction now. Maybe proving it by contradiction will be easier than directly.

Suppose $A\neq B$
Case $1: A\subseteq B$, since $A\neq B$ we have $y\in B$ so that $y\not\in A$, take any $x\in A$. Then $(x,y)\in A\times B$. On the other hand $(x,y)\not\in B\times A$, since $y\not\in A$. This shows $A\times B \neq B\times A$.
Case $2: A\not \subseteq B$, then there is $x$ so that $x\in A$ but $x\not \in B$, take any $y\in B$. Then $(x,y)\in A\times B$, but $(x,y)\not\in B\times A$, since $x\not\in B$. This shows $A\times B \neq B\times A$,
