The code http://pastebin.com/tq75PA7H
Spoiler
And here is a picture for clarification. The red button is where it prints the first time the program is run. The second time it prints where the green button is and continues working after that. I have also tried it with different sized screens and it prints in the wrong position the first time no matter what the size. Also, the button changes color correctly no matter which position it is in.
Spoiler













