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

📄 infomenu.java

📁 这是一个手机上的J2ME程序
💻 JAVA
字号:
// J2ME Compass
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/compass

package org.qcontinuum.compass;

import java.util.*;
import javax.microedition.lcdui.*;
import org.qcontinuum.astro.*;

public class InfoMenu extends List implements CommandListener {
    
    private Displayable mParent;
    private Command mBackCommand, mOkCommand;

    public InfoMenu(Displayable parent) {
        super("Info", List.IMPLICIT);
        mParent = parent;
        append("Time", null);
        append("Sun", null);
        append("Moon", null);
        append("Twilight", null);
        if (Compass.getPreferences().getDestination() != null)
            append("Destination", null);
        addCommand(mBackCommand = new Command("Cancel", Command.CANCEL, 1));
        addCommand(mOkCommand = new Command("OK", Command.OK, 1));
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)  {
        if (c == mOkCommand || c == List.SELECT_COMMAND) {
            switch (getSelectedIndex()) {
                case 0:
                    infoTime();
                    break;
                case 1:
                    Compass.display(new InfoSun(this));
                    break;
                case 2:
                    Compass.display(new InfoMoon(this));
                    break;
                case 3:
                    Compass.display(new InfoTwilight(this));
                    break;
                case 4:
                    infoDestination();
                    break;
            }
        } else if (c == mBackCommand) {
            Compass.display(mParent);
        }
    }
    
    public void infoTime() {
        InfoDisplay infoDisplay = new InfoDisplay("Time", this);
        Preferences preferences = Compass.getPreferences();
        Location location = preferences.getLocation();
        Location destination = preferences.getDestination();
        Date localDate = Compass.getDate();
        Date gmtDate = location.getGmt(localDate);
        infoDisplay.append(new StringItem("Location:", Compass.getTime(new UtcDate(localDate)) + "\n"));
        infoDisplay.append(new StringItem("GMT:", Compass.getTime(new UtcDate(gmtDate)) + "\n"));
        if (destination != null && destination.timeZone != null) {
            Date destinationDate = destination.getLocalTime(gmtDate);
            infoDisplay.append(new StringItem("Destination:", Compass.getTime(new UtcDate(destinationDate)) + "\n"));
        }
        Compass.display(infoDisplay);
    }

    public void infoDestination() {
        Date localDate = Compass.getDate();
        SunMoonPosition sunMoonPosition = new SunMoonPosition(localDate);
        EarthHeading destinationHeading = sunMoonPosition.getDestinationHeading();
        InfoDisplay infoDisplay = new InfoDisplay("Destination", this);
        if (destinationHeading != null) {
            infoDisplay.append(new StringItem("Heading:", destinationHeading.getHeading() + "癨n"));
            infoDisplay.append(new StringItem("Distance:", (destinationHeading.getMetres() / 1000) + " km\n"));
        }
        Compass.display(infoDisplay);
    }

}

⌨️ 快捷键说明

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