Use color in J2ME mobile program development

Source: Internet
Author: User
Tags getcolor

In J2ME mobile phone development process, need to often use color to draw, enhance the performance of the program, the following describes how to use color.

Because the J2ME technology is relatively simple, it does not implement a specialized color class, but only uses the concept of RGB to represent color. Here is a brief introduction to the concept of RGB, color is made of red, green (blue), the three primary colors, so you can use the combination of these three colors to represent a specific color, where r, G, B, each value is located between 0-255. When the color is expressed, it can be expressed in three digits, or it can be expressed in a hexadecimal format such as 0X00RRGGBB, which is the expression of a common color:

Red: (255,0,0) or 0x00ff0000

Green: (0,255,0) or 0x0000ff00

Blue: (255,255,255) or 0X00FFFFFF

Other colors can also be combined in the above way. When you know how colors are expressed, here's how to use colors in J2ME programs, and the methods involved are in the graphics class, with the following:

1.getColor ():

Gets the currently used color, and the return value is a number in 0X00RRGGBB format. For example:

int color = G.getcolor ();

Where G is an object of type graphics.

2.setColor (int RGB):

Sets the color to use. For example:

G.setcolor (0x00ff0000);

3.setColor (int red, int green, int blue)

As with the above method, for example:

G.setcolor (255,0,0);

After you set the color used by graphics, you can draw the specified color when you draw it.

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.