Introduction to the Java Color class

Source: Internet
Author: User

Java.awt.Color

1. Common sense of color

Any color is composed of three primary colors (RGB), Java support 224 for color, that is, the red-green-blue component value

Between 0-255 (8-bit representation)

Constants in the 2.Color class

Public final static Color black = new color (0,0,0);

Public final static Color bule = new color (0,0,255);

.

.

There are a number of such constants that we can call directly to the class name without having to instantiate it.

Constructors in 3.Color

Public Color (int r,int g,int b); Of course there are other methods of construction, and this is just one of the most common ones.

Example: Construct a Gray object: color Gray = new color (205,205,205);

4. Set Brush color syntax

First, get the brush: Graphics g = image.getgraphics ();//The image here is an object

Then set the brush color: G.setcolor (Color.Blue);

5. How to set the picture background through the graphics

You can first set the color of the brush, which is the background color you want to set: G.setcolor (color), then use the method G.fillrec (x,y,width,height), fill it, and fill it with the specified shape. and

The color is set to the top of the color, so there is a specified background of the graphic.

Introduction to the Java Color class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.