Java Swing Tutorial - Java Color(int r, int g, int b, int a) Constructor








Syntax

Color(int r, int g, int b, int a) constructor from Color has the following syntax.

@ConstructorProperties(value ={"red","green","blue","alpha"})public Color(int r,        int g,        int b,        int a)

Example

In the following code shows how to use Color.Color(int r, int g, int b, int a) constructor.

import java.awt.Color;
/*from w w w.j  av  a  2s.  co  m*/
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {
  public static void main(String[] args) {
    Color myBlack = new Color(0,0,0,120);           // Color black

    JLabel label = new JLabel("First Name");
    label.setForeground(myBlack);

    JFrame frame = new JFrame();
    frame.add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20,20, 500,500);
    frame.setVisible(true);

    
  }
}