Well there's more than one way to skin a cat (as I often think just after my cat pees on something), but here's what I'd do:
I'd create the main class where most of the application runs (let's call it MainClass just to be creative) and another class derived from the thread class to listen to the parallel port and report back to MainClass when it hears something. We'll call it ParallelListener just because I'm funny that way.
ParallelListener would look something like this:
The way you'd create a ParallelListener in your MainClass is straightforward:
Note that in the ParallelListener class, after getting some signal from the parallel port and decoding it's meaning, I'd call methods on the MainClass to take whatever action necessary to handle it (but that's just me).
Also, note that you shut down the ParallelListener thread by calling it's stopRunning() method like this:
*** Added the following to post ***
Note that programming robots can be tricky buisness, especially if you have to worry about real-time concern like collisions, time sensitive processes, etc (I used to program industrial robots awhile back). Polling for I/O needs to be done in it's own thread and that thread needs to share CPU time with everybody else or "Bad Things(tm)" will happen. Play with the timeing of the sleep command to get a balance between sharing the cpu and responsiveness to commands from the parallel port.
Java, while my favorite language is not the most effective choice for this sort of thing. May I ask why you chose it for programming a robot?
*** End of additional posting ***
I hope that helps.
Regards,
Tim Manchester
[ September 11, 2006: Message edited by: Tim Manchester ]
[ September 12, 2006: Message edited by: Tim Manchester ]