allow me one more comment,
i had a hard time testing your code,
as i am used to put in lots of
println(" function name: variable name: "+variable);
when i code ( combined with a global switch to enable/disable this diagnostic )
so i get little bit angry when i must run
fullscreen code and can not see the console.
actually i just see the bounce after i used that printing ( for state > 0 )
AND take out -1000 from your screen / button x settings
to see both windows.