import java.awt.*; import java.applet.*; // public class MovingText extends BasicAnimationApplet { int x, y; // position of the text int vx, vy; // velocity of the text String text_to_animate; TextField tf = new TextField(":)"); public void init() { x = 0; y = 50; vx = 4; vy = 5; add(tf); } public void step() { int width = getSize().width; // width of applet window int height = getSize().height; // height of applet window x += vx; y += vy; if (x > width) { // bounce vx = -vx; x = width; } if (x < 0) { vx = -vx; // bounce x = 0; } if (y > height) { // bounce vy = -vy; y = height; } if (y < 0) { vy = -vy; // bounce y = 0; } } public void paint(Graphics g) { text_to_animate = tf.getText(); g.drawString(text_to_animate, x, y); } }