Total members 11892 |It is currently Fri Oct 18, 2024 1:31 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 7336 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     -  
 deal with colors in java     -  
 Drawing a triangle with colors     -  
 Table Border Colors for PHPBB3     -  
 Making Colors Transparent with imagecolortransparent()     -  
 different colors for table Even- Odd rows and Cells     -  
 Image Colors Frequencies Histogram in Java     -  
 Re: An example show what is LAN     -  
 show the content of set     -  
 Show Progress Bar using JQuery     -  



Topic Tags

Java Graphics
cron





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