Java 获取屏幕的宽、高

时间:2024-03-12 19:51:55
1 import java.awt.Toolkit;
2 
3 public class GetScreenSize {
4     public static void main(String[] args) {
5         int screenWidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
6         int screenHeight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
7         System.out.println("The width of screen is " + screenWidth + ", and the height of screen is " + screenHeight);        
8     }
9 }

 

 1 import java.awt.Dimension;
 2 import java.awt.Toolkit;
 3  
 4 public class GetScreenSize {
 5     public static void main(String[] args) {
 6         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 7         int screenWidth = (int)screenSize.getWidth();
 8         int screenHeight = (int)screenSize.getHeight();
 9         System.out.println("The width of screen is " + screenWidth + ", and the height of screen is " + screenHeight);
10     }
11 }

 

 

参考:https://blog.csdn.net/m_wbcg/article/details/55548654