java gui大小_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、付费专栏及课程。

余额充值