new Color(int rgb) : Color « java.awt « Java by API






new Color(int rgb)

  

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;

class MyCanvas extends JComponent {
  Color[] colors = new Color[24];

  public MyCanvas() {
    int  rgb = 0xff;
    for (int i = 0; i < 24; i++) {
      colors[i] = new Color(rgb);
      rgb <<= 1;
      if ((rgb & 0x1000000) != 0) {
        rgb |= 1;
        rgb &= 0xffffff;
      }
    }
  }

  public void paint(Graphics g) {
    int i = 10;
    for (Color c : colors) {
      g.setColor(c);
      i += 10;
      g.drawLine(i, 10, 200, 200);
    }
  }
}

public class Main {
  public static void main(String[] a) {
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setBounds(30, 30, 300, 300);
    window.getContentPane().add(new MyCanvas());
    window.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.Color.GRAY
2.Color.lightGray
3.Color.magenta
4.Color.pink
5.new Color(int r, int g, int b)
6.Color: equals(Object obj)
7.Color: getComponents(float[] compArray)
8.Color: getRGB()
9.Color: HSBtoRGB(float hue,float saturation,float brightness)
10.Color: RGBtoHSB(int r, int g, int b, float[] hsbvals)