Path: blob/master/test/jdk/java/awt/FullScreen/AllFramesMaximize/AllFramesMaximize.java
41154 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 819076726* @key headful27* @requires os.family == "mac"28* @summary If JFrame is maximized on OS X, all new JFrames will be maximized by default29* @compile AllFramesMaximize.java30* @run main/manual AllFramesMaximize31*/3233import javax.swing.JFrame;34import javax.swing.JButton;35import javax.swing.JTextArea;36import javax.swing.SwingUtilities;37import java.awt.FlowLayout;38import java.awt.event.ActionEvent;39import java.awt.event.ActionListener;4041public class AllFramesMaximize {42private static JButton passButton;43private static JButton failButton;44private static JTextArea instructions;45private static JFrame mainFrame;46private static JFrame instructionFrame;47public static boolean isProgInterruption = false;48static Thread mainThread = null;49static int sleepTime = 300000;5051public static void createAndShowJFrame() {52passButton = new JButton("Pass");53passButton.setEnabled(true);5455failButton = new JButton("Fail");56failButton.setEnabled(true);5758instructions = new JTextArea(8, 30);59instructions.setText(" This is a manual test\n\n" +60" 1) Click on the maximize button, JFrame will enter fullscreen\n" +61" 2) Click anywhere on the JFrame\n" +62" 3) Press Pass if new JFrame didn't open in fullscreen,\n" +63" 4) Press Fail if new JFrame opened in fullscreen");6465instructionFrame = new JFrame("Test Instructions");66instructionFrame.setLocationRelativeTo(null);67instructionFrame.add(passButton);68instructionFrame.add(failButton);69instructionFrame.add(instructions);70instructionFrame.setSize(200,200);71instructionFrame.setLayout(new FlowLayout());72instructionFrame.pack();73instructionFrame.setVisible(true);7475passButton.addActionListener(new ActionListener() {76@Override77public void actionPerformed(ActionEvent ae) {78dispose();79isProgInterruption = true;80mainThread.interrupt();81}82});8384failButton.addActionListener(new ActionListener() {85@Override86public void actionPerformed(ActionEvent ae) {87dispose();88isProgInterruption = true;89mainThread.interrupt();90throw new RuntimeException("New JFrame opened on a new window!");91}92});9394mainFrame = new JFrame();95JButton button = new JButton("Open Frame");96mainFrame.getContentPane().add(button);97button.addActionListener(98new ActionListener() {99public void actionPerformed(ActionEvent e) {100JFrame f = new JFrame();101f.setSize(400, 400);102f.setVisible(true);103}104});105mainFrame.setSize(500, 500);106mainFrame.setVisible(true);107}108109private static void dispose() {110mainFrame.dispose();111instructionFrame.dispose();112}113114public static void main(String[] args) throws Exception {115mainThread = Thread.currentThread();116SwingUtilities.invokeAndWait(AllFramesMaximize::createAndShowJFrame);117118try {119mainThread.sleep(sleepTime);120} catch (InterruptedException e) {121if (!isProgInterruption) {122throw e;123}124} finally {125SwingUtilities.invokeAndWait(AllFramesMaximize::dispose);126}127128if (!isProgInterruption) {129throw new RuntimeException("Timed out after " + sleepTime / 1000130+ " seconds");131}132}133}134135136137