Toolkit.getDefaultToolkit()方法返回null,我该如何修复它?我想获得屏幕宽度和高度

时间:2014-07-15 06:33:23

标签: java screen toolkit dimension

Toolkit.getDefaultToolkit()方法返回null, 我该怎么解决?我想获得这样的屏幕宽度和高度 - > Dimension screenSize =(Dimension)(Toolkit.getDefaultToolkit()。getScreenSize()); int creenHeight = screenSize.height; int screenWidth = screenSize.width;

1 个答案:

答案 0 :(得分:0)

GraphicsDevice monitors[]=GraphicsEnvironment.getScreenDevices(); 

Dimension screen_resolution[monitors.length];

for (int monitorID = 0; monitorID < monitors.length; monitorID++)
{
    screen_resolution[monitorID] = new Dimension(monitors[monitorID].getDisplyMode().getWidth(),monitors[monitorID].getDisplyMode().getHeight());
}