h = minimap.getSize().height; w = minimap.getSize().width; if(x+w > screenSize.width) { x = 0; } if(y+h > screenSize.height) { y = 0; } minimapW.setLocation(x,y);
    public void initialize() {        menuBar = new CommonMenuBar(this.getClient());        initializeFrame();        try {            client.game.addGameListener(gameListener);            // Create the board viewer.            bv = new BoardView1(client.game, frame, this);            // Place the board viewer in a set of scrollbars.            scroller = new Panel();            scroller.setLayout (new BorderLayout());            Scrollbar vertical = new Scrollbar (Scrollbar.VERTICAL);            Scrollbar horizontal = new Scrollbar (Scrollbar.HORIZONTAL);            scroller.add (bv, BorderLayout.CENTER);            // Scrollbars are broken for "Brandon Drew" <brandx0@hotmail.com>            if (System.getProperty                    ("megamek.client.clientgui.hidescrollbars", "false").equals //$NON-NLS-1$ //$NON-NLS-2$                    ("false")) { //$NON-NLS-1$                // Assign the scrollbars to the board viewer.                scroller.add (vertical, BorderLayout.EAST);                scroller.add (horizontal, BorderLayout.SOUTH);                bv.setScrollbars (vertical, horizontal);            }        } catch (IOException e) {            doAlertDialog(Messages.getString("ClientGUI.FatalError.title"), Messages.getString("ClientGUI.FatalError.message") + e); //$NON-NLS-1$ //$NON-NLS-2$            die();        }        layoutFrame();        frame.setVisible(true);        menuBar.addActionListener(this);        frame.addKeyListener(this);        frame.addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e) {                frame.setVisible(false);                saveSettings();                die();            }        });        UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(frame);        if (!MechSummaryCache.getInstance().isInitialized()) {            unitLoadingDialog.setVisible(true);        }        uo = new UnitOverview(this);        bv.addDisplayable(uo);        bv.addMouseListener(this);        bv.addKeyListener(this);        bv.add(popup);        Dimension screenSize = frame.getToolkit().getScreenSize();        int x,y,h,w;        mechW = new Dialog(frame, Messages.getString("ClientGUI.MechDisplay"), false); //$NON-NLS-1$        x = GUIPreferences.getInstance().getDisplayPosX();        y = GUIPreferences.getInstance().getDisplayPosY();        h = GUIPreferences.getInstance().getDisplaySizeHeight();        w = GUIPreferences.getInstance().getDisplaySizeWidth();        if(x + w > screenSize.width) {            x = 0;            w = Math.min(w, screenSize.width);        }        if(y + h > screenSize.height) {            y = 0;            h = Math.min(h, screenSize.height);        }        mechW.setLocation(x, y);        mechW.setSize(w, h);        mechW.setResizable(true);        mechW.addWindowListener(this);        mechW.addKeyListener(this);        mechD = new MechDisplay(this);        mechD.addMechDisplayListener(bv);        mechW.add(mechD);        // added by kenn        Ruler.color1 = GUIPreferences.getInstance().getRulerColor1();        Ruler.color2 = GUIPreferences.getInstance().getRulerColor2();        ruler = new Ruler(frame, this.client, bv);        x = GUIPreferences.getInstance().getRulerPosX();        y = GUIPreferences.getInstance().getRulerPosY();        h = GUIPreferences.getInstance().getRulerSizeHeight();        w = GUIPreferences.getInstance().getRulerSizeWidth();        if(x + w > screenSize.width) {            x = 0;            w = Math.min(w, screenSize.width);        }        if(y + h > screenSize.height) {            y = 0;            h = Math.min(h, screenSize.height);        }        ruler.setLocation(x,y);        ruler.setSize(w,h);        // end kenn        // minimap        minimapW = new Dialog(frame, Messages.getString("ClientGUI.MiniMap"), false); //$NON-NLS-1$        x = GUIPreferences.getInstance().getRulerPosX();        y = GUIPreferences.getInstance().getRulerPosY();        if(x+20 > screenSize.width) {            x = 0;        }        if(y+20 > screenSize.height) {            y = 0;        }        minimapW.setLocation(x,y);        try {            minimap = new MiniMap(minimapW, this, bv);        } catch (IOException e) {            doAlertDialog(Messages.getString("ClientGUI.FatalError.title"), Messages.getString("ClientGUI.FatalError.message1") + e); //$NON-NLS-1$ //$NON-NLS-2$            die();        }        minimap.addKeyListener(this);        minimapW.addWindowListener(this);        minimapW.addKeyListener(this);        minimapW.add(minimap);        cb = new ChatterBox(this);        this.add(cb.getComponent(), BorderLayout.SOUTH);        client.changePhase(IGame.PHASE_UNKNOWN);        mechSelectorDialog = new MechSelectorDialog(this, unitLoadingDialog);        customBADialog = new CustomBattleArmorDialog(this, unitLoadingDialog);        new Thread(mechSelectorDialog, "Mech Selector Dialog").start(); //$NON-NLS-1$        new Thread(customBADialog, "Custom Battle Armor Dialog").start();    }