Java GUI之位置控制与尺寸控制

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值