1、- 1 - 外文原文 Simple Animation and Threads The first thing I ever saw Java do was an animation: a large red “Hi there!” that ran across the screen from the right to left. Even that simple form of animation was enough to make me stop and think, “this is really cool.” That sort of simple animation takes
2、only a few methods to implement in Java, but those few methods are the basis for any Java applet that you want to update the screen dynamically.Starting with simple animations is a good way to build up to the more complicated applets.Today, youll learn the fundamentals of animation in Java: how the
3、various parts of the system all work together so that you can create moving figures and dynamic updateable applets.Specifically, youll explore the following: How Java animations workthe paint() and repaint() methods, starting and stopping dynamic applets, and how to use and override these methods in
4、 your own applets. Threadswhat they are and how they can make your applets more well-behaved with other applets and with the Java system in general. Reducing animation flicker, a common problem with animation in Java. Throughout today, youll also work with lots of examples of real applets that creat
5、e animations or perform some kind of dynamic movement. Creating Animation in Java Animation in Java involves two steps: constructing a frame of animation, and then asking Java to paint that frame. Repeat as necessary to create the illusion of movement. The basic, static applets that you created yest
6、erday taught you how to accomplish the first part; all thats left is how to tell Java to paint a frame. Painting and Repainting The paint() method, as you learned yesterday, is called by Java whenever the applet needs to be paintedwhen the applet is initially drawn, when the window containing it is moved, or when another window is moved from over it. You can also, however, ask Java to repaint the applet at a time you choose. So, to change the appearance of what is on the screen, you const