The Dimension class encapsulates the width and height of a component (in integer precision) in a single object.The class is associated with certain properties of components. Several methods defined by the Component class and the LayoutManager interface return a Dimension object. 

解决方案 »

  1.   

    Dimension类是用来管理component(容器)大小的。比如:
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height) {
          frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
          frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);