Isolate logic using functional interface and execute it with Funxion utility class which can be found from the following link:

https://github.com/rcw3bb/gosu-funxion