创建一个新窗口,通过getSize()获取这个窗口的宽、高。

 

 1 import javax.swing.JFrame;
 2 
 3 public class WindowInTheMiddle extends JFrame {
 4     
 5     
 6     public static void main(String[] args) {
 7         WindowInTheMiddle window = new WindowInTheMiddle();
 8         window.launchFrame();
 9         
10         // Width & Height
11         System.out.println(window.getSize().getWidth());
12         System.out.println(window.getSize().getHeight());
13     }
14     
15     public void launchFrame() {
16         this.setTitle("Hello World! I'm coming!");
17         this.setSize(500, 500);
18         this.setLocation(300, 300);
19         this.setVisible(true);
20     }
21 }

 

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2021-10-19
  • 2021-04-23
  • 2022-12-23
  • 2022-02-18
  • 2021-12-03
  • 2021-12-09
猜你喜欢
  • 2021-05-23
  • 2021-11-27
  • 2021-09-20
  • 2021-11-27
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案