Code example for Preferences

Methods: getInt

0
         
        Dimension preferredSize = window.getPreferredSize();
        Dimension minSize = window.getMinimumSize();
         
        Rectangle bounds = new Rectangle(
                prefs.getInt(name+".x", 0),
                prefs.getInt(name+".y",0),
                Math.max(minSize.width,prefs.getInt(name+".width", preferredSize.width)),
                Math.max(minSize.height,prefs.getInt(name+".height", preferredSize.height))
                ); 
         
        if (! screenBounds.contains(bounds)) {
            bounds.x = screenBounds.x + (screenBounds.width - bounds.width) / 2;
            bounds.y = screenBounds.y + (screenBounds.height - bounds.height) / 2;
            Rectangle.intersect(screenBounds, bounds, bounds);
        } 
        window.setBounds(bounds);
         
        window.addComponentListener(new ComponentAdapter() {
            public void componentMoved(ComponentEvent evt) {
                prefs.putInt(name+".x", evt.getComponent().getX());