Use the font and color in the programming of the mobile phone

Source: Internet
Author: User

   Font

In the mobile programming of j2-based mobile phones, we can use the Font class to achieve better performance in the low-level user interface. How can we use the Font class?

First, due to restrictions on mobile phone devices, the Font types supported by mobile phones are very limited. Therefore, you can only use the default Font supported by mobile phones to construct Font-type objects. The following describes how to create a Font Class Object:

GetFont (int face, int style, int size );

For example:

Font font = Font. getFont (Font. FACE_SYSTEM, Font. STYLE_BOLD, Font. SIZE_MEDIUM );

No matter which parameter, you can only use the value set by the system. The specific size of these values may be different on different mobile phones. The following describes the values of the three parameters in detail:

The face parameter indicates the font appearance. The value can be:

FACE_MONOSPACE -- same width font

FACE_PROPORTIONAL -- balanced font

FACE_SYSTEM -- System font

The style parameter indicates the font style. The value can be:

STYLE_BOLD -- bold

STYLE_ITALIC -- Italic

STYLE_PLAIN -- normal

STYLE_UNDERLINED -- underline

STYLE_BOLD | STYLE_ITALIC -- bold italic

STYLE_UNDERLINED | STYLE_BOLD -- underlined and bold

STYLE_UNDERLINED | STYLE_ITALIC -- italic with underline

STYLE_UNDERLINED | STYLE_ITALIC | STYLE_BOLD -- bold italic with underlines

The size parameter indicates the font size. The value can be:

SIZE_SMALL -- small

SIZE_MEDIUM -- medium

SIZE_LARGE -- large

The preceding parameter values can be used to combine the font objects you need.

Below are some common font operations:

1. Obtain the default font of the system:

Font font = Font. getDefaultFont ();

2. In the panit method, if the Graphics parameter is named g, the method for obtaining the current font is:

Font font = g. getFont ();

3. In the panit method, if the Graphics parameter is named g, the current font is set as follows:

G. setFont (font );

Font indicates the font object you have constructed.

4. In MIDP2.0, you can set the font format of each line in List:

List. setFont (0, font );

The above Code sets the first line in the list as a font.
Use color

Color is often used for painting during the development process of the mobile phone program for enhancing the performance of the program. The following describes how to use color.

Due to the relatively simple technology, the special color class is not implemented, but the RGB concept is used to represent the color. Here we will briefly introduce the concept of RGB. colors are composed of three primary colors: Red, Green, and Blue, therefore, the combination of these three colors can be used to represent a specific color. Each value of R, G, and B is between 0 and. When expressing colors, you can use three numbers or a hexadecimal format, such as 0X00RRGGBB. The following is a common expression of colors:

Red :( 255, 0, 0) or 0x00FF0000
Green: (0,255, 0) or 0x0000FF00
Blue: (255,255,255) or 0x00FFFFFF

Other colors can also be combined through the above method.

After learning about the color expression, we will introduce how to use the color in the j2s program. The methods involved are in the Graphics class, including the following:

1. getColor ():

Obtain the current color. The returned value is a number in 0x00RRGGBB format. For example:

int color = g.getColor();
Where g is a Graphics type object.

2. setColor (int RGB ):

Set the color used. For example:

g.setColor(0x00ff0000);
3. setColor (int red, int green, int blue)

It works the same way as the preceding method, for example:

g.setColor(255,0,0);
After the color used by Graphics is set, you can draw the specified color.

Related Article

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.