0

我有一个中央数据库,我用 JDBC 连接到它,在对数据进行了一些准备之后,我生成了 6 个不同的 JFrame,我喜欢在建筑物的不同墙壁上的不同显示器(监视器)上显示每个,我可以到达只能通过 IP(通过 WiFi)同时进行。我可以用 GraphicsEnvironment 以某种方式解决它吗?

我会很感激任何建议!

4

1 回答 1

0

如果操作系统可以将每个屏幕视为单独的图形设备,您应该可以使用类似...

import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class TestGC {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }
                GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
                for (GraphicsDevice sd : sds) {
                    System.out.println(sd.getIDstring());
                    GraphicsConfiguration gc = sd.getDefaultConfiguration();
                    JFrame f = new JFrame(gc);
                    f.add(new JLabel(sd.getIDstring()));
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.pack();
                    centerOn(f, gc);
                    f.setVisible(true);
                }
            }
        });
    }

    private static void centerOn(JFrame f, GraphicsConfiguration gc) {
        Rectangle bounds = gc.getBounds();
        int x = bounds.x + ((bounds.width - f.getWidth()) / 2);
        int y = bounds.y + ((bounds.height - f.getHeight()) / 2);
        f.setLocation(x, y);
    }
}
于 2013-05-03T15:20:49.760 回答