在Java中屏幕尺寸 [英] Screen Size in Java

查看:466
本文介绍了在Java中屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在用Java的游戏,我使用DefaultToolkit得到屏幕尺寸,但与该问题是,是检测是否有人FULLSCREEN屏幕的大小。我怎样才能得到的游戏画面(这不是全屏)占用面积的屏幕尺寸。为了更precise,我的精灵正在超越底部屏幕边缘,因为系统工具栏里面添加额外的填充给它。我怎样才能得到的游戏画面占用面积的大小?非常感谢你。

Hello I am making a game in Java and I get the screenSize using DefaultToolkit, but the problem with that is that is detects the size of the screen if it was FULLSCREEN. How can I get the screen size of the area the game screen (which is not fullscreen) takes up. To be more precise, my sprite is moving beyond the edge of the bottom screen because of the system tool bar which add extra "padding" to it. How can I get the size of the Area the Game Screen takes up? Thank you very much

推荐答案

我觉得屏幕边界是你在找什么:

I think Screen Bounds is what you are looking for:

import java.awt.*;
import javax.swing.*;

public class FrameInfo
{
    public static void main(String[] args)
    {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle bounds = env.getMaximumWindowBounds();
        System.out.println("Screen Bounds: " + bounds );

        GraphicsDevice screen = env.getDefaultScreenDevice();
        GraphicsConfiguration config = screen.getDefaultConfiguration();
        System.out.println("Screen Size  : " + config.getBounds());
        System.out.println(Toolkit.getDefaultToolkit().getScreenSize());

        JFrame frame = new JFrame("Frame Info");
        frame.setSize(200, 200);
        frame.setVisible( true );

        System.out.println("Frame Size   : " + frame.getSize() );
        System.out.println("Frame Insets : " + frame.getInsets() );
        System.out.println("Content Size : " + frame.getContentPane().getSize() );
     }
}

这篇关于在Java中屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆