20-CS-694 Advanced Programming Techniques Spring 2012

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

    All lectures

Threads: Drawing and Animation

This series shows how to use some of the classes associated with animating objects. Click on the class names in the following table to see class details.

Thread Graphics Image Toolkit

1.   Checkers.java

  -   A thread is started and every 50 milliseconds it causes a checker to move slightly and be repainted on a bicolor background. There is some flicker.
2.   Checkers1.java

  -   The flicker of the above is reduced because only the area whose colors change as a result of the checker movement are repainted. This is accomplished with method clipRect of class Graphics.
3.   CheckersDouble.java

  -   Double buffering eliminates all the flicker.
4.   RBA.java

  -   Simple animation of objects - only paint is used. Eight dots are drawn at home positions. Drag dots, with the mouse to another position. Release the mouse button and dots will return to their home positions. The last "touched" dot is always brought to the top (draws over all other dots). Observe the object trails as they are moved from home positions.

MyObjectList is a doubly linked list of cells holding Dot objects. Its purpose is to support the illusion that one dot is "on top of" another. The head of the list holds the dot that is on the "bottom" and the tail holds the dot that is on the "top". Searching for a dot when the mouse button is pressed starts from the tail. But drawing dots starts from the head. Hence a doubly linked list is most efficient.

5.   RBB.java

  -   There is no double buffering in this applet but the background is painted to erase dots from frame to frame. Observe the flicker.
6.   RBC.java

  -   Trails and flicker are gone due to double buffering.
7.   Race.java
  -   Demonstrates the effect of synchronized when applied to the critical section update.
8.   Fib.java

  -   With StackCanvas and CodeCanvas classes, painting Canvases during window events is possible. Drawing to an offscreen image insures correct painting will appear after window events occur.
9.   Gas.java

  -   Use of threads to control time critical process. Point mouse and click at several places in both chambers. Click on the 'Start' button to start the simulation. Edit the temperature fields during the simulation and see the effect.
10.   Ballplay.java

  -   Nice use of threads.