< prev index next >

test/jdk/javax/swing/JFrame/4962534/bug4962534.java

Print this page


   1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  test
  26  @bug 4962534 7104594

  27  @summary JFrame dances very badly
  28  @author dav@sparc.spb.su area=
  29  @run applet bug4962534.html
  30  */
  31 import java.applet.Applet;
  32 import java.awt.*;
  33 import java.awt.event.*;
  34 import java.util.Random;
  35 import javax.swing.*;
  36 
  37 public class bug4962534 extends Applet {
  38 
  39     Robot robot;
  40     volatile Point framePosition;
  41     volatile Point newFrameLocation;
  42     JFrame frame;
  43     Rectangle gcBounds;
  44     Component titleComponent;
  45     JLayeredPane lPane;
  46     volatile boolean titleFound = false;
  47     public static Object LOCK = new Object();
  48 
  49     @Override





  50     public void init() {
  51         try {
  52             SwingUtilities.invokeAndWait(new Runnable() {
  53                 @Override
  54                 public void run() {
  55                     createAndShowGUI();
  56                 }
  57             });
  58         } catch (Exception ex) {
  59             throw new RuntimeException("Init failed. " + ex.getMessage());
  60         }
  61     }//End  init()
  62 
  63     @Override
  64     public void start() {
  65         validate();
  66 
  67         try {
  68             setJLayeredPaneEDT();
  69             setTitleComponentEDT();
  70         } catch (Exception ex) {
  71             ex.printStackTrace();
  72             throw new RuntimeException("Test failed. " + ex.getMessage());
  73         }
  74 
  75         if (!titleFound) {
  76             throw new RuntimeException("Test Failed. Unable to determine title's size.");
  77         }
  78 
  79         Random r = new Random();
  80 
  81         for (int iteration = 0; iteration < 10; iteration++) {
  82             try {
  83                 setFramePosEDT();
  84             } catch (Exception ex) {
  85                 ex.printStackTrace();
  86                 throw new RuntimeException("Test failed.");


 132 
 133             if (frameIsOutOfScreen) {
 134                 throw new RuntimeException("Test failed. JFrame is out of screen.");
 135             }
 136 
 137         } //for iteration
 138         System.out.println("Test passed.");
 139     }// start()
 140 
 141     private void createAndShowGUI() {
 142         try {
 143             UIManager.setLookAndFeel(
 144                     "javax.swing.plaf.metal.MetalLookAndFeel");
 145         } catch (Exception ex) {
 146             throw new RuntimeException(ex.getMessage());
 147         }
 148         JFrame.setDefaultLookAndFeelDecorated(true);
 149         frame = new JFrame("JFrame Dance Test");
 150         frame.pack();
 151         frame.setSize(450, 260);

 152         frame.setVisible(true);
 153     }
 154 
 155     private void setJLayeredPaneEDT() throws Exception {
 156 
 157         SwingUtilities.invokeAndWait(new Runnable() {
 158             @Override
 159             public void run() {
 160                 lPane = frame.getLayeredPane();
 161                 System.out.println("JFrame's LayeredPane " + lPane);
 162             }
 163         });
 164     }
 165 
 166     private void setTitleComponentEDT() throws Exception {
 167 
 168         SwingUtilities.invokeAndWait(new Runnable() {
 169             @Override
 170             public void run() {
 171                 for (int j = 0; j < lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue()).length; j++) {


   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   @test
  26   @key headful
  27   @bug 4962534
  28   @summary JFrame dances very badly
  29   @run main bug4962534

  30  */
  31 
  32 import java.awt.*;
  33 import java.awt.event.*;
  34 import java.util.Random;
  35 import javax.swing.*;
  36 
  37 public class bug4962534 {
  38 
  39     Robot robot;
  40     volatile Point framePosition;
  41     volatile Point newFrameLocation;
  42     JFrame frame;
  43     Rectangle gcBounds;
  44     Component titleComponent;
  45     JLayeredPane lPane;
  46     volatile boolean titleFound = false;
  47     public static Object LOCK = new Object();
  48 
  49     public static void main(final String[] args) {
  50         bug4962534 app = new bug4962534();
  51         app.init();
  52         app.start();
  53     }
  54 
  55     public void init() {
  56         try {
  57             SwingUtilities.invokeAndWait(new Runnable() {
  58                 @Override
  59                 public void run() {
  60                     createAndShowGUI();
  61                 }
  62             });
  63         } catch (Exception ex) {
  64             throw new RuntimeException("Init failed. " + ex.getMessage());
  65         }
  66     }//End  init()
  67 

  68     public void start() {


  69         try {
  70             setJLayeredPaneEDT();
  71             setTitleComponentEDT();
  72         } catch (Exception ex) {
  73             ex.printStackTrace();
  74             throw new RuntimeException("Test failed. " + ex.getMessage());
  75         }
  76 
  77         if (!titleFound) {
  78             throw new RuntimeException("Test Failed. Unable to determine title's size.");
  79         }
  80 
  81         Random r = new Random();
  82 
  83         for (int iteration = 0; iteration < 10; iteration++) {
  84             try {
  85                 setFramePosEDT();
  86             } catch (Exception ex) {
  87                 ex.printStackTrace();
  88                 throw new RuntimeException("Test failed.");


 134 
 135             if (frameIsOutOfScreen) {
 136                 throw new RuntimeException("Test failed. JFrame is out of screen.");
 137             }
 138 
 139         } //for iteration
 140         System.out.println("Test passed.");
 141     }// start()
 142 
 143     private void createAndShowGUI() {
 144         try {
 145             UIManager.setLookAndFeel(
 146                     "javax.swing.plaf.metal.MetalLookAndFeel");
 147         } catch (Exception ex) {
 148             throw new RuntimeException(ex.getMessage());
 149         }
 150         JFrame.setDefaultLookAndFeelDecorated(true);
 151         frame = new JFrame("JFrame Dance Test");
 152         frame.pack();
 153         frame.setSize(450, 260);
 154         frame.setLocationRelativeTo(null);
 155         frame.setVisible(true);
 156     }
 157 
 158     private void setJLayeredPaneEDT() throws Exception {
 159 
 160         SwingUtilities.invokeAndWait(new Runnable() {
 161             @Override
 162             public void run() {
 163                 lPane = frame.getLayeredPane();
 164                 System.out.println("JFrame's LayeredPane " + lPane);
 165             }
 166         });
 167     }
 168 
 169     private void setTitleComponentEDT() throws Exception {
 170 
 171         SwingUtilities.invokeAndWait(new Runnable() {
 172             @Override
 173             public void run() {
 174                 for (int j = 0; j < lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue()).length; j++) {


< prev index next >