1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* Print Hello World in an Applet in different Colors Example This Java example shows how to create an applet which shows "Hello World" text in different colors using Java Applet and Color classes. */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; /* <applet code = "HelloWorldInDifferentColorsExample" width = 300 height = 300> </applet> */ public class HelloWorldInDifferentColorsExample extends Applet{ public void paint(Graphics g){ Color c[] = {Color.blue,Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow}; for(int i = 0; i<c.length; i++){ g.setColor(c[i]); g.drawString("Hello World...",10,10 + (i*10)); } } } |
Add Comment