--- old/java/awt/Component/GetScreenLocTest/GetScreenLocTest.java 2015-08-25 17:18:45.000000000 +0300 +++ new/java/awt/Component/GetScreenLocTest/GetScreenLocTest.java 2015-08-25 17:18:44.000000000 +0300 @@ -1,50 +1,52 @@ /* - test - @bug 4356202 - @summary Tests that getLocationOnScreen returns valid value(WindowMaker only). - @author dom@sparc.spb.su: area= - @run applet GetScreenLocTest.html -*/ - -// Note there is no @ in front of test above. This is so that the -// harness will not mistake this file as a test file. It should -// only see the html file as a test file. (the harness runs all -// valid test files, so it would run this test twice if this file -// were valid as well as the html file.) -// Also, note the area= after Your Name in the author tag. Here, you -// should put which functional area the test falls in. See the -// AWT-core home page -> test areas and/or -> AWT team for a list of -// areas. -// Note also the 'GetScreenLocTest.html' in the run tag. This should -// be changed to the name of the test. - - -/** - * GetScreenLocTest.java + * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. * - * summary: + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; - -//Automated tests should run as applet tests if possible because they -// get their environments cleaned up, including AWT threads, any -// test created threads, and any system resources used by the test -// such as file descriptors. (This is normally not a problem as -// main tests usually run in a separate VM, however on some platforms -// such as the Mac, separate VMs are not possible and non-applet -// tests will cause problems). Also, you don't have to worry about -// synchronisation stuff in Applet tests they way you do in main -// tests... - +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; -public class GetScreenLocTest extends Applet -{ +/** + * @test + * @bug 4356202 + * @summary Tests that getLocationOnScreen returns valid value(WindowMaker + * only). + * @author dom@sparc.spb.su: area= + */ +public class GetScreenLocTest { //Declare things used in the test, like buttons and labels here - Robot robot = null; - private class MyCanvas extends Canvas { + static Robot robot = null; + private static class MyCanvas extends Canvas { public Dimension getPreferredSize() { return new Dimension(100, 100); } @@ -55,70 +57,56 @@ g.fillRect(0, 0, r.width, r.height); } } - Canvas c = null; - int state = 0; // there are three states - (-1,-1),(0,0),(1,1) - Frame f = null; - Frame bigOne = null; - void bigPause() { + static int state = 0; // there are three states - (-1,-1),(0,0),(1,1) + + static void bigPause() { Toolkit.getDefaultToolkit().sync(); robot.waitForIdle(); robot.delay(1000); } - public void init() - { - //Create instructions for the user here, as well as set up - // the environment -- set the layout manager, add buttons, - // etc. - - this.setLayout (new BorderLayout ()); - - try { - robot = new Robot(); - } catch(AWTException e) { - throw new RuntimeException(e.getMessage()); - } - bigOne = new Frame(); - bigOne.setBounds(10, 10, 140, 170); + + static void doPress(Point p) { + robot.mouseMove(p.x, p.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + public static void main(final String[] args) throws AWTException { + robot = new Robot(); + Frame bigOne = new Frame(); + bigOne.setSize(200, 200); + bigOne.setLocationRelativeTo(null); bigOne.setVisible(true); - f = new Frame(); + Frame f = new Frame(); f.setLayout(new BorderLayout()); - f.setBounds(20, 20, 120, 150); - f.add(c = new MyCanvas(), BorderLayout.CENTER); + f.setSize(120, 150); + f.setLocationRelativeTo(null); + Canvas c = new MyCanvas(); + f.add(c, BorderLayout.CENTER); c.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - switch(state) { - case 0: // the first event should be (0,0) - if (e.getX() != 0 || e.getY() != 0) { - throw new RuntimeException("wrong location " + e); - } - state++; - break; - case 1: // the second event should be (1,1) - if (e.getX() != 1 || e.getY() != 1) { - throw new RuntimeException("wrong location " +e); - } - state++; - break; - case 2: // this should never happen - throw new RuntimeException("wrong location " + e); - } + public void mousePressed(MouseEvent e) { + switch(state) { + case 0: // the first event should be (0,0) + if (e.getX() != 0 || e.getY() != 0) { + throw new RuntimeException("wrong location " + e); + } + state++; + break; + case 1: // the second event should be (1,1) + if (e.getX() != 1 || e.getY() != 1) { + throw new RuntimeException("wrong location " +e); + } + state++; + break; + case 2: // this should never happen + throw new RuntimeException("wrong location " + e); } - }); + } + }); f.pack(); f.setVisible(true); bigPause(); - }//End init() - void doPress(Point p) { - robot.mouseMove(p.x, p.y); - robot.mousePress(InputEvent.BUTTON1_MASK); - robot.mouseRelease(InputEvent.BUTTON1_MASK); - } - public void start () - { - //Get things going. Request focus, set size, et cetera - setSize (200,200); - show(); Point p = c.getLocationOnScreen(); doPress(p); p.x += 1; @@ -127,12 +115,14 @@ p.x -= 2; p.y -= 2; doPress(p); - bigPause(); + + f.dispose(); + bigOne.dispose(); + // ...and at the end the state should be 2 if (state != 2) { - throw new RuntimeException("wrong state"); + throw new RuntimeException("wrong state: " + state); } - }// start() - -}// class GetScreenLocTest + } +}