Java多屏显示(主屏幕,扩展屏)怎么实现?
发布网友
发布时间:2022-05-07 01:54
我来回答
共1个回答
热心网友
时间:2023-10-11 15:33
public class test
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setSize(400, 400);
jf.setDefaultCloseOperation(3);
jf.setVisible(true);
test.showOnScreen2(1, jf);
}
//screen 显示器序号
public static void showOnScreen2(int screen, JFrame frame)
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
if (screen > -1 && screen < gd.length)
{
frame.setLocation(gd[screen].getDefaultConfiguration().getBounds().x, frame.getY());
} else if (gd.length > 0)
{
frame.setLocation(gd[0].getDefaultConfiguration().getBounds().x, frame.getY());
} else
{
throw new RuntimeException("No Screens Found");
}
}
}