Web Hosting Tomcat, Java, JSP, Servlets, J2EE, PHP, MySQL

Cheap web hosting provider

30
Sep

Black Art of Java Game Programming by Joel

Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Previous Table of Contents Next To run this applet, update the Mondrian.html file from Chapter 1 with the following applet tag. (In future applets, we ll assume that you know how to create the applet tag in the HTML file.) Compile the source and run it with appletviewer or a Web browser. Although this applet is a bit more complex than its predecessor, it has methods that you learned about in Chapter 1 init(), start(), paint(), and stop() that are called at various stages in the applet s lifetime. Broadway.java has one extra method, run(). Can you guess what it does before reading on? Using the Universal Animation Loop The run() method should look familiar. It is a Java version of the Universal Animation Loop, so it draws the current frame, updates the center rectangle for the next frame, and pauses before looping back to the top. Let s examine the loop in more detail. The first line of run() is a call to repaint(), which is defined in the Applet class. Remember that Broadway is a subclass of Applet, so it inherits all of Applet s methods. The method repaint() is one of these, and calling it has two effects: 1. It clears the screen. 2. It draws the current frame of the animation, by calling paint(). Thus, paint() is the Applet method that actually draws to the screen; repaint() redraws the screen by calling paint(). The second method of run() is called updateRectangle(), which computes the newest location of the center rectangle and stores it in the variables locx and locy, which mark the rectangle s upper-left corner. This has the effect of moving the rectangle for the next animation frame. The last line of run() causes a delay of 100 milliseconds (.1 seconds) before looping back to the top and repeating the entire process, for a frame rate of around 10 fps. Thread.sleep() refers to the static method of the Thread class named sleep(); recall that static methods are invoked by prefixing the
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services

Comments are closed.