Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
How to show Rainbow Colors 
 

The Rainbow consists of seven colors known as VIBGYOR i.e. violet, indigo, blue, green, yellow, orange and red color.

 

How to show Rainbow Colors

                         

This section illustrates you how to show all the seven colors of colors.

The Rainbow consists of seven colors known as VIBGYOR i.e. violet, indigo, blue, green, yellow, orange and red color. We are providing you an example which shows all the seven colors of rainbow.

All the visible colors can be obtained by the primary colors red, green and blue. Therefore we have defined red, green and blue colors. The height and width of image is defined.

 Following code draws the image of seven colors.

g.drawImage(bufferedImage, 0, 0, this)

Here is the code of ShowRainbowColors.java 

import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class ShowRainbowColors extends JComponent {
  BufferedImage bufferedImage;

  public void initialize() {
    int wd= getSize().width;
    int ht = getSize().height;
    int[] data = new int[wd * ht];
    int index = 0;
    for (int j = 0; j < ht; j++) {
      int red = (j * 255) / (ht - 1);
      for (int k = 0; k < wd; k++) {
        int green = (k* 255) / (wd - 1);
        int blue = 128;
        data[index++] = (red << 16) | (green << 8) | blue;
      }
    }
    bufferedImage = new BufferedImage(wd, ht, BufferedImage.
     TYPE_INT_RGB);

    bufferedImage.setRGB(00, wd, ht, data, 0, wd);
  }
    public void paint(Graphics g) {
    if (bufferedImage == null)
      initialize();
    g.drawImage(bufferedImage, 00this);
  }
public static void main(String[] args) {
    JFrame frame = new JFrame("Show Rainbow Colors");
    frame.getContentPane().add(new ShowRainbowColors());
    frame.setSize(450300);
    frame.setLocation(100100);
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
        System.exit(0);
      }
    });
    frame.setVisible(true);
  }
}

Output will be displayed as:

Download Source Code

                         

» View all related tutorials
Related Tags: c string com class orm ant form object io sed format screen font display vi metrics id render oo define

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.