Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:12 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: show Rainbow Colors
PostPosted: Tue Nov 11, 2008 6:07 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

show Rainbow Colors
Code:
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(0, 0, wd, ht, data, 0, wd);
  }
    public void paint(Graphics g) {
    if (bufferedImage == null)
      initialize();
    g.drawImage(bufferedImage, 0, 0, this);
  }
public static void main(String[] args) {
    JFrame frame = new JFrame("Show Rainbow Colors");
    frame.getContentPane().add(new ShowRainbowColors());
    frame.setSize(450, 300);
    frame.setLocation(100, 100);
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
        System.exit(0);
      }
    });
    frame.setVisible(true);
  }
}


Output will be displayed as:
Attachment:
rainbowColors.gif
rainbowColors.gif [ 50.32 KiB | Viewed 1293 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Show image using before property
 Show image when click on link
 two Different background colors
 image slide show
 show all files in a directory with detail
 show all drivers in file system
 Drawing a triangle with colors
 How to show full resolution image at clicking on thumnail
 Table Border Colors for PHPBB3
 How to Show a message before the login ?

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 3 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team