28
Sep
Black Art of Java Game Programming by Joel
name, java.applet.Applet, when it s needed. It gets pretty inconvenient to type such long names, however, so Java allows you to import a class or package. The import statement import java.applet.Applet; at the start of the source file allows you to use Applet as a shorthand for the fully qualified name. Another form of the import statement, import java.applet.*; allows you to use the unqualified class names for all the classes in the package java.applet. Let s jump right in. This applet, shown in Listing 1-7, is called Mondrian.java, and you ll soon see why. Listing 1-7 Mondrian applet import java.applet.*; import java.awt.*; public class Mondrian extends Applet { public void init() { System.out.println(”>> init <<"); setBackground(Color.black); } public void start() { System.out.println(">> start <<"); } // paint squares of varying colors public void paint(Graphics g) { System.out.println(">> paint <<"); g.setColor(Color.yellow); g.fillRect(0,0,90,90); g.fillRect(250,0,40,190); g.fillRect(80,110,100,20); g.setColor(Color.blue); g.fillRect(80,200,220,90); g.fillRect(100,10,90,80);
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services
