Switch to full style
General Java code examples
Post a reply

show Rainbow Colors

Tue Nov 11, 2008 6:07 pm

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:
rainbowColors.gif




Post a reply
  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