There is a better way to do this, but I don't know if it is what you want.
You can have you entire paint in another class, then just add it as the paint listener on script start, or where ever you need it.
I think its like, script.addPaintListener(new YOURPAINTCLASS)
Then just implement the paint listener in that class and tada you're done