email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

Timing

 

To do animation or anything that requires delay, in the builder, just drag over animation. It adds two things to your code (so you could do it manually).

In initialize, it adds :

 

setAnimation(true);

 

 

It also adds another method - update which gets called automatically every 50 milliseconds.Update gets the temporary layer and when you are done, it will automatically call drawScreen putting up that temporary layer.



              //the method below will get called every frame.
              //its argument g is the temporary graphics layer
              public void update(Graphics g)
              {
              //put your code for what should happen each animation
              
              }
              
      

 

Assignment:

 

In a class called HWJ10_Text, have some fun text (use g.drawString("text",x,y);

  1. move back and forth on the screen.
  2. Add code so that every 40 times it moves the color changes between green and red.
  3. Add code so that when they press 1-3 the animation changes speed. (either change global variable speed, or change the delay - which already is a global variable)
  4. Add two buttons (or 1) that stops the animation and a button to start the animation.

Advanced:

 

  1. Make the text get bigger and smaller link
  2. Have it so the text bounce around the screen like a ball. Have a it start in a random location and move in a random direction.

You can update the amount of delay (frame rate) by saying:

setDelay(80);

You can stop animation by saying:

stop();

You can start animation by saying:

start();