/********************
由於無法上傳附件,cds.exe請到csdn下載!
http://download.csdn.net/source/3317043
附件出處:http://home.no/aksoftware/ 第三個,QRes
********************/
import java.io.IOException;
/**
*
*修改解析度
* @author cmxie
*/
public class ChangeDisplaySettings {
public static boolean change(int w,int h)
{
String cmd = "";
try {
if (WindowsOrLinux.getSystemType()) {// 判斷系統:Window 系統
//附件為cds.exe檔案。該檔案是封裝好的修改解析度的小工具。直接調用傳入參數即可。
cmd = " cmd "+System.getProperty("user.dir")+"/DownloadFileList/SOURCE/cds.exe /x "+w+" /y "+h;
Runtime.getRuntime().exec(cmd);
return true;
} else {// Linux 系統
//linux中使用命令 xrandr 來修改解析度
cmd = " xrandr -s "+w+"x"+h;
Runtime.getRuntime().exec(cmd);
return true;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static void main(String[] args) throws NativeException, IllegalAccessException{
ChangeDisplaySettings.change(1440,900);
}
}
/**
* 判斷作業系統
* @author cmxie
*
*/
public class WindowsOrLinux {
/**
* 擷取作業系統類型 true:windows false:linux
* @return
*/
public static boolean getSystemType()
{
String osName = System.getProperty("os.name");
if(osName!=null && !"".equals(osName)){
if (osName.matches("^(?i)Windows.*$")) {// Window 系統
return true;
}else
{
return false;
}
}
return true;
}
}
/**************** *java風暴* 63353324 技術聯盟*******************/