java 修改windows & linux 解析度。

來源:互聯網
上載者:User

/********************

由於無法上傳附件,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  技術聯盟*******************/

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.