Java Code Examples for java.awt.Frame#addWindowStateListener()

The following examples show how to use java.awt.Frame#addWindowStateListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NormalToIconifiedTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}
 
Example 2
Source File: NormalToIconifiedTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}
 
Example 3
Source File: NormalToIconifiedTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}
 
Example 4
Source File: NormalToIconifiedTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}
 
Example 5
Source File: NormalToIconifiedTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}
 
Example 6
Source File: NormalToIconifiedTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}
 
Example 7
Source File: NormalToIconifiedTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame testFrame = new Frame("Test Frame");
    testFrame.setSize(200, 200);
    testFrame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent e) {
            listenerNotified.set(true);
            synchronized (listenerNotified) {
                listenerNotified.notifyAll();
            }
        }
    });
    testFrame.setVisible(true);

    Frame mainFrame = new Frame("Main Frame");
    mainFrame.setSize(200, 200);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setVisible(true);

    Util.waitForIdle(robot);

    try {
        Util.clickOnComp(mainFrame, robot);
        Util.waitForIdle(robot);

        // NORMAL -> ICONIFIED
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
                    "ICONIFIED transition");
        }
        if (testFrame.getExtendedState() != Frame.ICONIFIED) {
            throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
        }

        // ICONIFIED -> NORMAL
        listenerNotified.set(false);
        testFrame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(robot);

        Util.waitForCondition(listenerNotified, 2000);
        if (!listenerNotified.get()) {
            throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
                    "NORMAL transition");
        }
        if (testFrame.getExtendedState() != Frame.NORMAL) {
            throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
        }
    } finally {
        testFrame.dispose();
        mainFrame.dispose();
    }
}