Modified to work with a JFrame and gameloop.