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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Icon showing Color Gradient 
 

A color gradient consisting of two or more colors blending together. To display the icon, we have defined the height and width of an image.

 

Icon showing Color Gradient

                         

This section illustrates you how the icon shows the Color Gradient.

A color gradient consisting of two or more colors blending together. To display the icon, we have defined the height and width of an image. To produce pixel values for an Image, we have used the class MemoryImageSource which is an implementation of the interface ImageProducer 

 The method getPreferredSize() is used to determine the arrangement of layout and indicates the preferred size. 

Following code draws the image:

g.drawImage(image, 0, 0, getSize().width, getSize().height, this)

Here is the code of IconShowingColorGradient.java

import java.awt.*;
import java.awt.image.MemoryImageSource;

public class IconShowingColorGradient extends Component {
    public static void main(String[] args) {
    Frame frame = new Frame("Color Gradient");
    frame.add(new IconShowingColorGradient());
    frame.setIconImage(new IconShowingColorGradient(1616).getImage());
    frame.setSize(100100);
    frame.show();
  }
private Image image;
private int width;
private int height;
public IconShowingColorGradient() {
    this(100100);
  }
public IconShowingColorGradient(int w, int h) {
    this.width = w;
    this.height = h;
    int pixel[] = new int[w * h];
    int ind = 0;
    for (int x = 0; x < h; x++) {
      int color1 = (x * 255) / (h - 1);
      for (int y = 0; y < w; y++) {
        int color2 = (y * 255) / (w - 1);
        pixel[ind++] = (255<<16) | (color1 << 24) | color2;
      }
    }
    image = createImage(new MemoryImageSource(w, h, pixel, 0,w));
    setSize(getPreferredSize());
  }
public Image getImage() {
    return image;
  }
public Dimension getPreferredSize() {
    return new Dimension(width, height);
  }
public void paint(Graphics g) {
    g.drawImage(image, 00, getSize().width, getSize().height, this);
  }
}

Output will be displayed as

Download Source code

                         

» View all related tutorials
Related Tags: c class orm form io method sed format 2d get ip translation return instance transform show for transformation to draw

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.