Oracle's swing tutorials don't typically do the most graceful approaches, but they are very excellent nonetheless.
You'll want to hit the swing tutorials up for frames, buttons and event handlers. Then you can move the applet since its super easy to wrap the swing with an applet.
For splitting, you have two classes there, the thinkiner and the runner. The runner there is your cli application running on a command line with command line input and output. The thinker simply processes what has to happen. Separating them means you can use it in either a command line interface or in a gui, without needing to change the logic at all. The interface simply changes.
header('HTTP/1.1 420 Enhance Your Calm');