以下四个类都包含在java.awt包内。1. Toolkit类:Toolkit类是一个包含了本机系统属性和参数的抽象类,比如Clipboard内容、光标、桌面属性、字体族、颜色类型、屏幕参数和系统事件。2. Dimension类:Dimension类通常用来获取或设置组件的尺寸。与Toolkit类配合使用,则可以获取屏幕尺寸。3. GraphicsEnvironment类:GraphicsEnvironment类是一个包含本级系统图像环境的类。4. Rectangle类:Rectangle类是矩形类。
- package com.sinosuperman.driver;
-
- import java.awt.Dimension;
- import java.awt.GraphicsEnvironment;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
-
- public class MainBench {
- public static void main(String[] args) {
- // Get a Toolkit object containing system properties and parameters.
- Toolkit tk = Toolkit.getDefaultToolkit();
- // Get a Dimension object containing screen size.
- Dimension d = tk.getScreenSize();
- // Get the screen width.
- System.out.println(d.getWidth());
- // Get the screen height.
- System.out.println(d.getHeight());
-
- // Get a GraphicsEnvironment object containing system graphics environment.
- GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
- // Get a Rectangle object containing the maximum window bounds of current window.
- Rectangle rec = environment.getMaximumWindowBounds();
- // Get the x-coordinate of the center point of rec.
- System.out.println(rec.getCenterX());
- // Get the y-coordinate of the center point of rec.
- System.out.println(rec.getCenterY());
- System.out.println(rec);
-
- // Get the center point of system graphics environment.
- Point point = environment.getCenterPoint();
- System.out.println(point);
-
- // Get the location of rec.
- point = rec.getLocation();
- System.out.println(point);
- }
- }
|