使用Java RunnableJar更改远程会话的屏幕分辨率

时间:2015-10-29 09:44:27

标签: java jar jframe fullscreen screen-resolution

更改当前系统的屏幕分辨率工作正常,但我需要更改远程会话的屏幕分辨率(可能在虚拟框中)。哪个是连接的,通过程序我需要改变它。表单基于Web的应用程序我将通过提供参数来调用runnable jar文件。

public static void main(String[] args) throws InterruptedException, IOException {
    screenResolution(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));   // Screen Resolution of Remote Session.
}

public static void screenResolution(int width, int height, int bitDepth, int refreshRate) throws InterruptedException{
    java.awt.GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    java.awt.DisplayMode change_Mode = new DisplayMode(width, height, bitDepth, refreshRate);//DisplayMode.REFRESH_RATE_UNKNOWN);
    DisplayMode[] supportedResolutions = graphicsDevice.getDisplayModes();
    System.out.println(supportedResolutions.length);
    for (DisplayMode resolution : supportedResolutions) {
        System.out.format("%d by %d, (%dbit), %d Hertz \n", resolution.getWidth(), resolution.getHeight(), resolution.getBitDepth(), resolution.getRefreshRate());
        if (resolution.equals(change_Mode)) {
            System.out.format("supported = %s\n",resolution);
            DisplayMode current_displayMode = graphicsDevice.getDisplayMode();
            if (change_Mode.equals(current_displayMode)) 
                System.out.println("=== No need to change Resolution ===");
            else {
                java.awt.GraphicsConfiguration graphConfig = graphicsDevice.getDefaultConfiguration();
                javax.swing.JFrame frame = new JFrame("",graphConfig);
                setResolution(graphicsDevice, frame, change_Mode);
            }
            break;
        }
    }
}
public static void setResolution(GraphicsDevice graphicsDevice, JFrame frame, DisplayMode displayMode) throws InterruptedException{
    try {
        graphicsDevice.setFullScreenWindow(frame);
        graphicsDevice.setDisplayMode(displayMode);
        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); 

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        System.out.println("After Cahange Resolution : "+screenSize.getWidth()+" * "+screenSize.getHeight());

        // doing other work......
        Thread.sleep(1*60*1000); // min sec millisec
    }catch(IllegalArgumentException e){
        e.printStackTrace();
    }finally{
        frame.dispose(); //program terminates. screen resolution changes to previous resolution.
    }
} 

从控制台D:\JarLocation>java -jar ChangeResolution.jar 1366 768 32 60在当前机器上运行我的jar文件,它运行正常。但我需要改变屏幕的分辨率,当客户有什么不同的分辨率来测试他的senario。

我在远程计算机上运行了相同的jar文件,但它无法更改。

即使手动也无法改变它。它说显示设置无法更改。

0 个答案:

没有答案