Total members 11895 |It is currently Thu Dec 26, 2024 12:19 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 wdgetSize().width;
    
int ht getSize().height;
    
int[] data = new int[wd ht];
    
int index 0;
    for (
int j 0htj++) {
      
int red = (255) / (ht 1);
      for (
int k 0wdk++) {
        
int green = (k255) / (wd 1);
        
int blue 128;
        
data[index++] = (red << 16) | (green << 8) | blue;
      }
    }
    
bufferedImage = new BufferedImage(wdhtBufferedImage.
     
TYPE_INT_RGB);
    
bufferedImage.setRGB(00wdhtdata0wd);
  }
    public 
void paint(Graphics g) {
    if (
bufferedImage == null)
      
initialize();
    
g.drawImage(bufferedImage00this);
  }
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:
Attachment:
rainbowColors.gif
rainbowColors.gif [ 50.32 KiB | Viewed 7394 times ]




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : show Rainbow Colors
 two Different background colors     -  
 Drawing a triangle with colors     -  
 deal with colors in java     -  
 Making Colors Transparent with imagecolortransparent()     -  
 different colors for table Even- Odd rows and Cells     -  
 Table Border Colors for PHPBB3     -  
 Image Colors Frequencies Histogram in Java     -  
 Re: An example show what is LAN     -  
 show the content of set     -  
 how to show hashmap value in a textbox     -  



Topic Tags

Java Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com