以下四個類都包含在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);
- }
- }