Java Tutorial

 
 
 
 
/* <applet code=\"ColorBar\" height=400 width=400> 
    </applet>  */

import java.awt.*;
import java.applet.*;

public class ColorBar extends Applet
{
    Color colors[]={ Color.blue, Color.cyan, Color.yellow, Color.red, Color.darkGray,
                               Color.gray, Color.lightGray, Color.magenta, Color.orange, Color.pink,
                               Color.white, Color.black};

        public void paint(Graphics g){
             Dimension d = getSize();
             int x = d.width/colors.length;
             setBackground(Color.lightGray);
             for (int i=0; i<colors.length ; i++ )
             {
                   g.setColor(colors[i]);
                   g.fillRect(i*x, 0, (i+1) * x, d.height);
             }
        }
}

    Related Post:
  1. Program to compute the sum of the digits of a given integer number. eg: I/o=4 then O/p=4+3+2+1=10

  2. Program to show the use of Switch Statement

  3. File handling program to copy characters from one file to another

  4. Program to show an example of using initialization block to initialize the data members of a class

  5. An applet program of passing parameters

  6. Program to ask question and accept answer up to 3 attempt and display right answer if it is wrong

  7. Encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time after each word in the sent

  8. Program to show the use of Conditional OR Operator (||) in If Statements

  9. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  10. Program to read the table elements into a two-dimensional array temperature

  11. Program to show an example of using constructors in a class to initialize its data members

  12. Program to show an example of extracting subStrings from a String

  13. Program that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform operation

  14. File handling program to copy bytes from one file to another

  15. An applet program that displays Text at the center of the string which is passed as parameter

  16. Program to show the use of Labeled Break Statement

  17. Program for Thread Priority

  18. Program to show an example of Concatination of Strings

  19. Program to show the use of operator (&gt;&gt;&gt;) Shift Right, filling with zeros from the left

  20. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

 
 
Didn't find what you were looking for? Find more on An applet program to display Vertical Color Bar