Re: Printing got Shuffled
Sounds like a threading problem but as I've no idea what you are doing it's hard to say.
If you've one instance of the applet then consider using a Queue from the java.util.concurrent package between the javascript calls and the rpinting sub system. The javascript calls (producer) add the data to the queue and return. Your applet has a background thread (consumer) which loops around calling the queue's take() method which blocks the thread until there is data to return. When it does return with the next data element this consumer thread prints the data and finally loops around to call take() again to get or wait for the next data.
Because the queue is a FIFO queue the print output is guaranteed to be in the order the data was added to the queue.