public void computeComponentSize() { // get our newly dragged out frame size Rectangle rFrameSize = this.getBounds(); // the following is true if going to or coming from a maximized state if ((this.getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { //e we determine if we ae going to or coming from if ((previousFrameState & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) { rFrameSize = savedFrameSize; previousFrameState = 0; } else { previousFrameState = this.getExtendedState(); } } else { previousFrameState = 0; savedFrameSize.height = rFrameSize.height; savedFrameSize.width = rFrameSize.width; savedFrameSize.x = MainWindow.pUpperLeftCorner.x; savedFrameSize.y = MainWindow.pUpperLeftCorner.y; } // this is the amount of space we can fill with images Dimension dPanelSize = new Dimension(rFrameSize.width - dOccupiedSpace.width, rFrameSize.height - dOccupiedSpace.height); long lArea = dPanelSize.width * dPanelSize.height; if (lArea <= 0) return; /* this computation is used to get a starting point for determing what the size of our images should be: namely, Area = Height * Width, h=w *(3/4), a = w^2 * (3/4), w = sqrt((4/3) a), so w = w * sqrt(a/3) */ int iWidth = (new Double(2 * Math.sqrt(lArea / (MainWindow.iNbrImages * 3)))).intValue(); int iHeight = iWidth * 3 / 4; int iNbrAcross = dPanelSize.width / iWidth; if (iNbrAcross == 0) ++iNbrAcross; int iNbrDown = MainWindow.iNbrImages / iNbrAcross; // might be even if (iNbrDown * iNbrAcross != MainWindow.iNbrImages) ++iNbrDown; while (((iNbrAcross * iWidth) > dPanelSize.width) || ((iNbrDown * iHeight) > dPanelSize.height) ) { iHeight = --iWidth * 3 / 4; iNbrAcross = dPanelSize.width / iWidth; if (iNbrAcross == 0) ++iNbrAcross; else if (iNbrAcross > MainWindow.iNbrImages) iNbrAcross = MainWindow.iNbrImages; iNbrDown = MainWindow.iNbrImages / iNbrAcross; if (iNbrDown * iNbrAcross != MainWindow.iNbrImages) ++iNbrDown; } nd.setSize(iWidth * iNbrAcross, iHeight * iNbrDown); CameraImage.dimension = new Dimension(iWidth, iHeight); this.setBounds(rFrameSize.x, rFrameSize.y, nd.width + dOccupiedSpace.width, nd.height + dOccupiedSpace.height); }