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

📄 timezonelist.java

📁 开发j2me 手机程序必须的用到的。文件较小
💻 JAVA
字号:

package com.jmobilecore.ui;

import com.jmobilecore.ui.core.*;
import com.jmobilecore.support.TimeZone;
import javax.microedition.lcdui.Graphics;

/**
 * The <code>TimeZoneList</code> component presents the user with a scrolling list of timezones.
 * @see com.jmobilecore.ui.core.List
 * @see com.jmobilecore.support.TimeZone
 *
 * @author Greg Gridin
 */
public class TimeZoneList extends List {

    /**
     * Creates a new timezone scrolling list.
     */
    public TimeZoneList(String label) {
        super(label);
        String[] timezoneIDs = TimeZone.getAvailableIDs();
        int[] timezoneOffs = TimeZone.getAvailableOffsets();
        final int len = timezoneIDs.length;
        for (int i = 0; i < len; i++) {
            String tz = timezoneIDs[i];
            int offSet = timezoneOffs[i] / (1000 * 60 * 60);
            add(new ListLabel(tz + " (GMT " + (offSet >= 0 ? "+" : "") + offSet + ":00)", Style.TEXT_FONT, PlatformCanvas.KEY_UNDEFINED, tz));
        }
    }

    /**
     * Paints the <code>PropertyLabel</code> to the screen.
     *
     * @param g The Graphics object to render to.
     */
    public void paint(Graphics g) {

        if (getBackground() != Color.TRANSPARENT) {
            g.setColor(getBackground());
            g.fillRect(0, screenY, width, height);
        }
        if (getForeground() != Color.TRANSPARENT) g.setColor(getForeground());
        if (font != null) g.setFont(font);
        int y = screenY + Style.V_GAP;
        g.drawString(text, Style.H_GAP, y, Graphics.TOP | Graphics.LEFT);
        int index = getSelectedIndex();
        if (index != -1) {
            g.drawString(TimeZone.getAvailableIDs()[index], this.width - Style.H_GAP, y, Graphics.TOP | Graphics.RIGHT);
        }
    }

    /**
     * Gets currently selected timezone id
     * Timezone id belongs to <code>TimeZone.getAvailableIDs()</code>
     *
     * @return timezone id
     */
    public String getTimeZoneID() {

        return (String) getSelectedComponent().getAction();
    }

    /**
     * Selects timezone by timezone id
     * Timezone id should be one of <code>TimeZone.getAvailableIDs()</code>
     *
     * @param tzID The timezone id
     * @return true if timezone was successfully selected, false otherwise
     */
    public boolean setTimeZoneID(String tzID) {

        if (tzID==null) return false;
        String[] timezoneIDs = TimeZone.getAvailableIDs();
        for (int i=0; i<timezoneIDs.length; i++) {
            if (tzID.equals(timezoneIDs[i])) {
                select(i);
                return true;
            }
        }
        return false;
    }

} // class TimeZoneList

⌨️ 快捷键说明

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