?? mapconfig.java
字號:
package com.oyc.mapxtreme.util;
import java.io.InputStream;
import java.util.Properties;
/**
* 地圖參數類,在全局范圍內保存地圖的各個參數
* @author 三峽大學理學院 歐陽超
*
*/
public class MapConfig {
//地圖參數
private static String mapxtremeurl;
private static String mappath;
private static String filetoload;
private static int mapwidth;
private static int mapheight;
//唯一實例
private static MapConfig mapCfg = new MapConfig();
/**
* 私有構造器
*
*/
private MapConfig(){
}
/**
* 取得本類的實例
* @return
*/
public synchronized static MapConfig getInstance(){
return mapCfg;
}
/**
* 加載地圖配置文件mapxtreme.properties
* @throws Exception
*/
public void config() throws Exception {
//加載配置文件
InputStream in = this.getClass().getClassLoader().getResourceAsStream("mapxtreme.properties");
if(in == null){
System.out.println("找不到配置文件mapxtreme.properties");
throw new Exception("找不到配置文件mapxtreme.properties");
}
Properties props = new Properties();
props.load(in);
//取出mapxtremeurl
mapxtremeurl = props.getProperty("mapxtremeurl");
if(mapxtremeurl==null || mapxtremeurl.trim().equals("")){
System.out.println("檢查mapxtreme配置文件屬性: \"mapxtremeurl\"");
throw new Exception("檢查mapxtreme配置文件屬性: \"mapxtremeurl\"");
}
//讀取地圖路徑
mappath = props.getProperty("mappath");
if(mappath==null || mappath.trim().equals("")){
System.out.println("檢查mapxtreme配置文件屬性: \"mappath\"");
throw new Exception("檢查mapxtreme配置文件屬性: \"mappath\"");
}
//讀取地圖文件
filetoload = props.getProperty("filetoload");
if(filetoload==null || filetoload.trim().equals("")){
System.out.println("檢查mapxtreme配置文件屬性: \"filetoload\"");
throw new Exception("檢查mapxtreme配置文件屬性: \"filetoload\"");
}
//讀取地圖寬度
String s_size = props.getProperty("mapwidth");
if(s_size==null || s_size.trim().equals("")){
System.out.println("檢查mapxtreme配置文件屬性: \"mapwidth\"");
throw new Exception("檢查mapxtreme配置文件屬性: \"mapwidth\"");
}else{
mapwidth = Integer.parseInt(props.getProperty("mapwidth"));
}
//讀取地圖高度
s_size = props.getProperty("mapheight");
if(s_size==null || s_size.trim().equals("")){
System.out.println("檢查mapxtreme配置文件屬性: \"mapheight\"");
throw new Exception("檢查mapxtreme配置文件屬性: \"mapheight\"");
}else{
mapheight = Integer.parseInt(props.getProperty("mapheight"));
}
}
/**
* 測試
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception{
mapCfg.config();
System.out.println("mapxtremeurl:" + mapCfg.getMapxtremeurl());
System.out.println("mappath:" + mapCfg.getMappath());
System.out.println("filetoload:" + mapCfg.getFiletoload());
System.out.println("mapwidth:" + mapCfg.getMapwidth());
System.out.println("mapheight:" + mapCfg.getMapheight());
}
public String getFiletoload() {
return filetoload;
}
public void setFiletoload(String filetoload) {
MapConfig.filetoload = filetoload;
}
public int getMapheight() {
return mapheight;
}
public void setMapheight(int mapheight) {
MapConfig.mapheight = mapheight;
}
public String getMappath() {
return mappath;
}
public void setMappath(String mappath) {
MapConfig.mappath = mappath;
}
public int getMapwidth() {
return mapwidth;
}
public void setMapwidth(int mapwidth) {
MapConfig.mapwidth = mapwidth;
}
public String getMapxtremeurl() {
return mapxtremeurl;
}
public void setMapxtremeurl(String mapxtremeurl) {
MapConfig.mapxtremeurl = mapxtremeurl;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -