[英]Java Jframe launch another JFrame to another X Server
我有一個在Xvnc(在Ubuntu上)屏幕(DISPLAY:1)上運行的Java應用程序,我需要做的是,從一個應用程序(即在DISPLAY中運行的一個)啟動另一個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();
只有1台設備。 未檢測到我的XVNC X11服務器(DISPLAY: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);
}
}
現在使用觀察者平台(偵聽器)在兩個框架之間進行更改...
不幸的是,TheBetaProgrammer解決方案是在同一顯示器的2個屏幕上而不是2個不同的顯示器上顯示JFrame。 我最近幾天一直在尋找相同的東西,但沒有找到任何簡單的方法來做到這一點。 到目前為止,我將在其自己的顯示器上分別擁有2個應用程序,並使用JGroups進行交談(我直接在2個應用程序之間發送動作事件)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.