zoukankan      html  css  js  c++  java
  • Java 创建一个窗口,使其启动时位于屏幕中间

     1 import java.awt.Toolkit;
     2 
     3 import javax.swing.JFrame;
     4 
     5 public class WindowInTheMiddle extends JFrame {
     6     public static void main(String[] args) {
     7         WindowInTheMiddle window = new WindowInTheMiddle();
     8         window.launchFrame();
     9     }
    10     
    11     public void launchFrame() {
    12         // The width & Height of the window
    13         final int formWidth = 500;
    14         final int formHeight = 500;
    15         // The width & Height of the screen
    16         int screenWidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    17         int screenHeight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    18         
    19         // Set title, size, location & visible
    20         this.setTitle("Hello World! I'm coming!");
    21         this.setSize(formWidth, formHeight);
    22         this.setLocation((screenWidth-formWidth)/2, (screenHeight-formHeight)/2);
    23         this.setVisible(true);
    24     }
    25 }
  • 相关阅读:
    2018年12月29日 Oracle查询性能优化
    B
    A
    洛谷 P2447 [SDOI2010]外星千足虫
    洛谷 P5358 [SDOI2019]快速查询
    欠的题目
    ZJU-ICPC Summer 2020 Contest 8 B-Picnic
    洛谷 P3164 [CQOI2014]和谐矩阵
    K
    J
  • 原文地址:https://www.cnblogs.com/Satu/p/9829737.html
Copyright © 2011-2022 走看看