⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertylabel.java

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 JAVA
字号:
package com.jmobilecore.ui;

import com.jmobilecore.ui.core.Style;
import com.jmobilecore.ui.core.Label;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

/**
 * Provides a component for displaying pair key-value on the screen.
 * The key is displayed left-justified, the value is right-justified.
 *
 * @author Greg Gridin
 */
public class PropertyLabel extends Label {

    /**
     * The key of this <code>PropertyLabel</code>. The key is displayed on
     * the left part of the screen
     *
     * @see #setKey(String)
     */
    public String key = null;

    /**
     * The value of this <code>PropertyLabel</code>. The key is displayed on
     * the right part of the screen
     *
     * @see #setValue(String)
     */
    public String value = null;

    /**
     * Constructs a new <code>PropertyLabel</code> that presents the specified
     * key and it's value displayed by default font
     *
     * @param key   the key for this <code>PropertyLabel</code>.
     *              A <code>null</code> value
     *              will be accepted without causing a NullPointerException
     *              to be thrown.
     *              The text can be single line only. If text contains
     *              \n characters (used to indicate line breaks) then <code>PropertyLabel</code>
     *              will be displayed incorrectly
     * @param value the value for this <code>PropertyLabel</code>.
     *              A <code>null</code> value
     *              will be accepted without causing a NullPointerException
     *              to be thrown.
     *              The text can be single line only. If text contains
     *              \n characters (used to indicate line breaks) then <code>PropertyLabel</code>
     *              will be displayed incorrectly
     */
    public PropertyLabel(String key, String value) {
        this(key, value, Style.TEXT_FONT);
    }

    /**
     * Constructs a new <code>PropertyLabel</code> that presents the specified
     * key and it's value displayed by specified font
     *
     * @param key   the key for this <code>PropertyLabel</code>.
     *              A <code>null</code> value
     *              will be accepted without causing a NullPointerException
     *              to be thrown.
     *              The text can be single line only. If text contains
     *              \n characters (used to indicate line breaks) then <code>PropertyLabel</code>
     *              will be displayed incorrectly
     * @param value the value for this <code>PropertyLabel</code>.
     *              A <code>null</code> value
     *              will be accepted without causing a NullPointerException
     *              to be thrown.
     *              The text can be single line only. If text contains
     *              \n characters (used to indicate line breaks) then <code>PropertyLabel</code>
     *              will be displayed incorrectly
     * @param font  the <code>PropertyLabel</code> font
     */
    public PropertyLabel(String key, String value, Font font) {

        super(null);
        this.font = font;

        setLabel(key, value);
    }

    /**
     * Sets the key for this <code>PropertyLabel</code> to the specified string.
     *
     * @param key the key for the <code>PropertyLabel</code>.
     */
    public void setKey(String key) {
        this.key = key;
    }

    /**
     * Sets the value for this <code>PropertyLabel</code> to the specified string.
     *
     * @param value the value for the <code>PropertyLabel</code>.
     */
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * This method was intentionally set to deprecated
     * @deprecated
     */
    public String getText() {
        return text;
    }

    /**
     * This method was intentionally set to deprecated
     * Use methods <code>setKey</code> and <code>setValue</code> instead
     * @deprecated
     */
    public void setText(String text) {
        this.text = text;
    }
    /**
     * Sets the key and the value for this <code>PropertyLabel</code>.
     *
     * @param key   the key for the <code>PropertyLabel</code>.
     * @param value the value for the <code>PropertyLabel</code>.
     */
    public void setLabel(String key, String value) {
        setKey(key);
        setValue(value);
        setHeight();
    }

    /**
     * Paints the <code>PropertyLabel</code> to the screen.
     *
     * @param g The Graphics object to render to.
     */
    public void paint(Graphics g) {
        paintBackground(g);
        prepareForeground(g);
        int y = screenY + Style.V_GAP;
        g.drawString(key, Style.H_GAP, y, Graphics.TOP | Graphics.LEFT);
        g.drawString(value, this.width - Style.H_GAP, y, Graphics.TOP | Graphics.RIGHT);
    }

    /**
     * Default destructor. Helps VM to perform garbage collection
     */
    public void destructor() {
        key = value = null;
        super.destructor();
    }
} // class PropertyLabel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -