GAMES LESSON TWO: Three Thread Idioms

There are three basic thread idioms:
Extending the Thread Class
Implementing Runnable
Anonymous Inner Class



All three thread idioms contain a run method. The run method in each case looks very much the same:
public void run(){ boolean move_rt = true; while(true){ if(move_rt && x>390){ move_rt = false; } if(!move_rt && x<5){ move_rt = true; } if(move_rt) mvX(3); else mvX(-3); try{ Thread.sleep(100); }catch(InterruptedException e){}; } }

There is a slight complication in the extending Thread example in which case the mvX method can only be reached by properly addressing the class instance in which it is contained (see the example).

The most efficient idiom in terms of space is the anonymous inner class method, but the problem there is that the code can be hard to follow since the inner class can sort of get lost in the outer class especially if the code for the inner class is lengthy.


ASSIGNMENT: