FileDocCategorySizeDatePackage
Framework.javaAPI DocExample4185Tue Dec 12 18:59:16 GMT 2000None

Framework

public class Framework extends WindowAdapter

(Omit source code)

Fields Summary
public int
numWindows
private Point
lastLocation
private int
maxX
private int
maxY
Constructors Summary
public Framework()


      
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        maxX = screenSize.width - 50; 
        maxY = screenSize.height - 50; 
        makeNewWindow();
    
Methods Summary
public static voidmain(java.lang.String[] args)

        Framework framework = new Framework();
    
public voidmakeNewWindow()

        JFrame frame = new MyFrame(this);
        numWindows++;
        System.out.println("Number of windows: " + numWindows);

        if (lastLocation != null) {
            //Move the window over and down 40 pixels.
            lastLocation.translate(40, 40);
            if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
                lastLocation.setLocation(0, 0);
            }
            frame.setLocation(lastLocation);
        } else {
            lastLocation = frame.getLocation();
        }

        System.out.println("Frame location: " + lastLocation);
        frame.setVisible(true);
    
public voidquit(javax.swing.JFrame frame)

        if (quitConfirmed(frame)) {
            System.out.println("Quitting.");
            System.exit(0);
        }
        System.out.println("Quit operation not confirmed; staying alive.");
    
private booleanquitConfirmed(javax.swing.JFrame frame)

        String s1 = "Quit";
        String s2 = "Cancel";
        Object[] options = {s1, s2};
        int n = JOptionPane.showOptionDialog(frame,
                "Windows are still open.\nDo you really want to quit?",
                "Quit Confirmation",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                s1);
        if (n == JOptionPane.YES_OPTION) {
            return true;
        } else {
            return false;
        }
    
public voidwindowClosed(java.awt.event.WindowEvent e)

        numWindows--;
        System.out.println("Number of windows = " + numWindows);
        if (numWindows <= 0) {
            System.out.println("All windows gone.  Bye bye!");
            System.exit(0);
        }