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

Create simple applet, print text in different colors using start method

  1. /* Applet Life Cycle */
  2. /*
  3.  init()
  4.  start()
  5.  stop()
  6.  destroy()
  7.  
  8. */
  9. import java.applet.Applet;
  10. import java.awt.Graphics;
  11. import java.awt.*;
  12. /*
  13.  <applet code = "Applet08" width = 500 height = 300>
  14.  </applet>
  15. */
  16. public class Applet08 extends Applet
  17. {
  18.  String s = "Hello World";
  19.  int i;
  20.  Color c[] = {Color.blue,Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray,
  21.        Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow};
  22.  public void init()
  23.  {
  24.   i = 0;
  25.  }
  26.  public void start()
  27.  {
  28.   if(i >= c.length-3)
  29.    i=0;
  30.   else
  31.    i++;
  32.  }
  33.  public void stop()
  34.  {
  35.  
  36.  }
  37.  public void destroy()
  38.  {
  39.   System.out.println("Destroyed..");
  40.  }
  41.  
  42.  public void paint(Graphics g)
  43.  {
  44.  
  45.   g.setFont(new Font("Sarif",Font.BOLD,20));
  46.   g.setColor(c[i]);
  47.   g.drawString(s,50,50);
  48.   g.setColor(c[i+1]);
  49.   g.drawString(s,50,80);
  50.   g.setColor(c[i+2]);
  51.   g.drawString(s,50,110);
  52.  
  53.  }
  54. }
Minimize the applet window and maximize it again to change the colors!
Your rating: None Average: 5 (1 vote)
Share this
Anonymous's picture

njnbhjbnhjb

njnbhjbnhjb

Post new comment

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