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.