Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Create simple applet and print string in different colors

  1. /* Using Colors */
  2. /* Syntax
  3.  Color(int R, int G, int B)
  4.  Color(int rgb)
  5.  Color(float r, float g, float b)
  6. */
  7. /* Color Cosntants { black, blue, cyan, darkGray, gray, green, ligntGray,
  8.        magenta, orange, pink, red, white, yellow}
  9. */
  10.  
  11. import java.applet.Applet;
  12. import java.awt.Graphics;
  13. import java.awt.Color;
  14. /*
  15.  <applet code = "Applet04" width = 300 height = 300>
  16.  </applet>
  17. */
  18. public class Applet04 extends Applet
  19. {
  20.  public void paint(Graphics g)
  21.  {
  22.   Color c[] = {Color.blue,Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray,
  23.        Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow};
  24.   for(int  i = 0; i<c.length; i++)
  25.   {
  26.    g.setColor(c[i]);
  27.    g.drawString("Hello World...",10,10 + (i*10));
  28.   }
  29.  }
  30. }
No votes yet
Share this

Post new comment

6 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.