【问题标题】:Java Jframe launch another JFrame to another X ServerJava Jframe 将另一个 JFrame 启动到另一个 X 服务器
【发布时间】:2014-04-03 14:13:42
【问题描述】:

我有一个在 Xvnc(在 Ubuntu 上)屏幕(DISPLAY :1)上运行的 java 应用程序,我需要做的是从一个应用程序启动另一个 JFrame 到主屏幕 DISPLAY :0,即正在运行的应用程序在显示中:1。

我曾考虑过使用 Runtime.getRuntime().exec(),但问题是,我需要从主应用程序控制第二个 JFrame 属性。

请帮助我如何实现这一目标。谢谢你。我不需要跨平台解决方案,只为ubuntu。

更新:

我用过代码

try{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();
    for(int i = 0; i < gd.length; i++){
        System.out.println(gd[i]);
    }
} catch (Exception e){
    e.printStackTrace();
}

而我只有一台显示器X11GraphicsDevice[screen=0],这意味着GraphicsDevice[] gd = ge.getScreenDevices(); 只有一台设备。未检测到我的 XVNC X11 服务器 (DISPLAY :1)。

【问题讨论】:

    标签: java swing jframe xserver


    【解决方案1】:

    以下是如何将框架设置为显示
    为类制作此实例数据:

    public class Graphic{
     private GraphicsEnvironment graphicsEnviorment;
     private DisplayMode dm, dm_old;
     private    JFrame frame1=new JFrame(), frame2 =new JFrame(); // we now have access to both jframes
    
    public void makeScreen(){
        graphicsEnviorment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    
        GraphicsDevice[] devices = graphicsEnviorment.getScreenDevices();
    
        dm_old = devices[0].getDisplayMode(); // replace 0 with screen #
        dm = dm_old;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    
        //place dead center on screen 
        int windowX = Math.max(0, (screenSize.width - frame.getWidth()) / 2);
        int windowY = Math.max(0, (screenSize.height - frame.getHeight()) / 2);
    
        frame1.setLocation(windowX, windowY);
    
                 frame1.setVisable(true);
                 // frame 2
    
                dm_old = devices[0].getDisplayMode(); // replace 0 with screen #
        dm = dm_old;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    
        //place dead center on screen 
        int windowX = Math.max(0, (screenSize.width - frame.getWidth()) / 2);
        int windowY = Math.max(0, (screenSize.height - frame.getHeight()) / 2);
        frame2.setLocation(windowX, windowY);
    
                 frame2.setVisable(true);
    
                }
    }
    

    现在使用观察者平台(侦听器)在两个帧之间手动更改...

    【讨论】:

    • 谢谢,我试过你的代码,但是使用 devices[1] 会给我 ArrayIndexOutOfBound 异常。请注意,我在尝试代码时激活了我的 XVNC 服务器。
    【解决方案2】:

    不幸的是,BetaProgrammer 的解决方案是在同一显示器的 2 个屏幕上显示 JFrame,而不是在 2 个不同的显示器上。在过去的几天里,我一直在寻找同样的东西,但没有找到任何简单的方法来做到这一点。到目前为止,我将有 2 个应用程序,每个应用程序都有自己的显示器,使用 JGroups 一起交谈(我在 2 个应用程序之间直接发送动作事件)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多