📄 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 + -