国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

App下載
首頁(yè)javajframeJava Swing - 如何在不同的顯示器上創(chuàng)建不同的JFrames

Java Swing - 如何在不同的顯示器上創(chuàng)建不同的JFrames

我們想知道如何在不同的顯示器上創(chuàng)建不同的JFrames。
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {

  public static void main(String[] args) {
    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);
  }
}