📜  jframe mittig positionieren - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:44.679000             🧑  作者: Mango

代码示例1
public class MyFrame {

   public MyFrame(String title) {
      JFrame frame = new JFrame(title);
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      int windowWidth = 800; //Breite des Programmfensters in Pixel
      int windowHeight = 600; //Höhe des Programmfensters in Pixel
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //Bildschirmdimensionen in Pixeln holen
      frame.setBounds((screenSize.width-windowWidth)/2, (screenSize.height-windowHeight)/2, windowWidth, windowHeight);
      frame.setVisible(true);
   }

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
              new MyFrame("Byte-Welt.net");
          }
      });
   }
}