JaVa
   

Summary

Although using threads is very complex, it is the task of the programmer to make the management of multiple threads as simple as possible. The easiest way to do this is to run all functionality in one thread. The problem is that functionality can be spawned from different threads, but we can limit this to a safe bare minimum. The main example of this is where mouse and keyboard events are concerned. They are accepted through the Event Dispatch Thread. Instead of handling these events in the event dispatch thread, we can add them to an event pump (basically a list), which can then be polled in the main loop thread and handled there. So there will be no synchronization problems with the functionality in the rest of the main loop. We will implement this feature in , "Using the Mouse and Keyboard."

I must confess, the synchronization elements of this chapter were perhaps among the most difficult things I've ever had to explain (well, that and explaining to my parents how, on a student loan, I managed to gamble £150 (pounds sterling) in one night). It is quite possible that this section went straight over your head. If so, I apologize, but do not worry, as there are many important practical thread synchronization issues that are covered in the rest of this tutorial, which should clear up any misunderstandings you have. We will now take on the visual side of coding games in Java. We must first begin with the very foundation of graphical representations in Java: visual apps and applets.

JaVa
   
Comments