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

📄 locationmap.java

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

package org.qcontinuum.compass;

import javax.microedition.lcdui.*;
import henson.midp.Float;
import java.io.IOException;

public class LocationMap extends MapCanvas implements CommandListener {

    private Command mLoadCommand, mSearchAirportCommand;
    private Command mZoomInCommand, mZoomOutCommand, mReligiousCommand, mClearCommand;
    private Command mOkCommand, mCancelCommand;
    private Location mLocation;
    private Displayable mParent;
    private boolean mDestination;

    public LocationMap(Displayable parent, boolean destination) {
        mParent = parent;
        mDestination = destination;
        Location location;
        if (mDestination)
            location = Compass.getPreferences().getDestination();
        else
            location = Compass.getPreferences().getLocation();
        if (location == null)
            mLocation = new Location();
        else
            mLocation = new Location(location);
        addCommand(mLoadCommand = new Command("Load", Command.SCREEN, 1));
        addCommand(mSearchAirportCommand = new Command("Airport", Command.SCREEN, 1));
        addCommand(mZoomInCommand = new Command("Zoom +", Command.SCREEN, 1));
        addCommand(mZoomOutCommand = new Command("Zoom -", Command.SCREEN, 1));
        addCommand(mClearCommand = new Command("Clear", Command.SCREEN, 1));
        if (mDestination)
            addCommand(mReligiousCommand = new Command("Religious", Command.SCREEN, 1));
        addCommand(mOkCommand = new Command("OK", Command.OK, 0));
        addCommand(mCancelCommand = new Command("Cancel", Command.CANCEL, 0));
        setCommandListener(this);
    }
    
    protected void paint(Graphics g) {
        super.paint(g);
        if (mLocation.Name != null) {
            g.setColor(0, 0, 0);
            g.drawString(mLocation.Name, 0, 0, Graphics.TOP|Graphics.LEFT);
        }
    }
    
    protected void locationChanged() {
        short latMinutes = (short)getLatitude().Mul(60).toLong();
        short longMinutes = (short)getLongitude().Mul(60).toLong();
        if (latMinutes != mLocation.LatMinutes || longMinutes != mLocation.LongMinutes) {
            mLocation.Name = null;
            mLocation.AirportCode = null;
            mLocation.timeZone = null;
            mLocation.LatMinutes = (short)getLatitude().Mul(60).toLong();
            mLocation.LongMinutes = (short)getLongitude().Mul(60).toLong();
        }
        super.locationChanged();
    }

    protected void locationSelected() {
        Compass.display("Please select the time zone for this location.", 5,
                new LocationTimeZone(mLocation, mDestination, mParent));
    }
    
    public void commandAction(Command c, Displayable d)  {
        if (c == mLoadCommand) {
            Compass.display(new LocationLoad(mDestination, this, mParent));
        } else if (c == mSearchAirportCommand) {
            Compass.display("Please enter the 3 or 4 letter code for the nearest airport. "
                + "For example, enter LHR for London Heathrow. "
                + "This code normally appears on luggage tags.",
                new LocationAirportCode(mLocation, this));
        } else if (c == mOkCommand) {
            locationSelected();
        } else if (c == mCancelCommand) {
            Compass.display(mParent);
        } else if (c == mZoomInCommand) {
            zoomIn();
        } else if (c == mZoomOutCommand) {
            zoomOut();
        } else if (c == mClearCommand) {
            Preferences preferences = Compass.getPreferences();
            if (mDestination)
                preferences.setDestination(null);
            else
                preferences.setLocation(null);
            preferences.save();
            Compass.setRefresh(true);
            Compass.display(mParent);
        } else if (mDestination && c == mReligiousCommand) {
            Compass.display(new LocationReligious(this, mParent));
        }
    }

    protected void showNotify() {
        super.showNotify();
        setLatitude(new Float(mLocation.LatMinutes).Div(60));
        setLongitude(new Float(mLocation.LongMinutes).Div(60));
    }
    
}

⌨️ 快捷键说明

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