28
Sep
Black Art of Java Game Programming by Joel
operations, such as drawing or filling, will use the given Color object. The sidebar shows a list of static constants that are defined in the Color class. To set the color to green, for example, use g.setColor(Color.green); // g is a Graphics object java.awt.Color Predefined colors: (These are static constants.) Grayscale: white, lightGray, gray, darkGray, black Other colors: red, green, blue, yellow, magenta, cyan, pink, orange Here s a little example of how to use these Graphics methods. Assume that the Graphics object g is passed into the paint() method: void paint(Graphics g) { g.setColor(Color.green); g.drawLine(17,17,273,273); g.drawLine(17,18,273,274); g.setColor(Color.red); g.fillRect(30,130,130,130); g.setColor(Color.yellow); g.fillOval(100,50,130,130); } This little masterwork is called Composition 2. Figure 1-15 shows what it looks like. Figure 1-15 Composition 2 Now it s time to combine your knowledge of Java and graphics into your first graphics applet! A Graphics Applet To write an applet, you must create a subclass of the Applet class. The Applet class is part of the java.applet package. To refer to the Applet class in your program, you can use its fully qualified
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services
