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 :
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
In a class called HWJ10_Text, have some fun text (use g.drawString("text",x,y);
- move back and forth on the screen.
- Add code so that every 40 times it moves the color changes between
green and red.
- 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)
- Add two buttons (or 1) that stops the animation and a button to start
- Make the text get bigger and smaller link
- 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:
You can stop animation by saying:
You can start animation by saying: