Java中获得屏幕宽度两种方法//GraphicsEnvironment 类描述了 Java(tm)
//应用程序在特定平台上可用的 GraphicsDevice
//对象和 Font 对象的集合。此 GraphicsEnvironment
//中的资源可以是本地资源,也可以位于远程机器上
//GraphicsDevice 对象可以是屏幕、打印机或图像缓冲区,
//并且都是 Graphics2D 绘图方法的目标。每个 GraphicsDevice
//都有许多与之相关的 GraphicsConfiguration 对象。
//这些对象指定了使用 GraphicsDevice 所需的不同配置。
/*GraphicsEnvironment 屏幕、打印机或图像缓冲区的屏幕宽度大小*/
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
//getLocalGraphicsEnvironment() 返回本地 GraphicsEnvironment
//getDefaultScreenDevice() 返回默认的屏幕 GraphicsDevice
GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
DisplayMode displayMode = graphicsDevice.getDisplayMode();
System.out.println (displayMode.getWidth());
System.out.println (displayMode.getHeight());
/*
*Toolkit类是所有 Abstract Window Toolkit 实际实现的抽象超类。
*Toolkit 的子类被用于将各种组件绑定到特定本机工具包实现。
**/
Toolkit tk = Toolkit.getDefaultToolkit();//得到Toolkit对象(实例化)
Dimension screen=tk.getScreenSize();//得到屏幕的大小
System.out.println (screen.getWidth());//输出屏幕的宽度
System.out.println (screen.getHeight());//输出屏幕的高度
TestFram tf = new TestFram();