Java 创建一个窗口,使其启动时位于屏幕中间

 import java.awt.Toolkit;

 import javax.swing.JFrame;

 public class WindowInTheMiddle extends JFrame {
public static void main(String[] args) {
WindowInTheMiddle window = new WindowInTheMiddle();
window.launchFrame();
} public void launchFrame() {
// The width & Height of the window
final int formWidth = 500;
final int formHeight = 500;
// The width & Height of the screen
int screenWidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int screenHeight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); // Set title, size, location & visible
this.setTitle("Hello World! I'm coming!");
this.setSize(formWidth, formHeight);
this.setLocation((screenWidth-formWidth)/2, (screenHeight-formHeight)/2);
this.setVisible(true);
}
}
上一篇:快手4.0 (KSCAD)


下一篇:DedeCms 5.x 本地文件包含漏洞(respond方法)