< prev index next >

test/java/awt/Frame/ShapeNotSetSometimes/ShapeNotSetSometimes.java

Print this page




  29   @run main ShapeNotSetSometimes
  30 */
  31 
  32 
  33 import java.awt.*;
  34 import java.awt.event.InputEvent;
  35 import java.awt.geom.*;
  36 
  37 
  38 public class ShapeNotSetSometimes {
  39 
  40     private Frame backgroundFrame;
  41     private Frame window;
  42     private static final Color BACKGROUND_COLOR = Color.BLUE;
  43     private Shape shape;
  44     private int[][] pointsToCheck;
  45 
  46     private static Robot robot;
  47 
  48     public ShapeNotSetSometimes() throws Exception {
  49         EventQueue.invokeAndWait(new Runnable() {
  50             public void run() {
  51                 initializeGUI();
  52             }
  53         });
  54     }
  55 
  56     private void initializeGUI() {
  57         backgroundFrame = new BackgroundFrame();
  58         backgroundFrame.setUndecorated(true);
  59         backgroundFrame.setSize(300, 300);
  60         backgroundFrame.setLocation(20, 400);
  61         backgroundFrame.setVisible(true);
  62 
  63         shape = null;
  64         String shape_name = null;
  65         Area a;
  66         GeneralPath gp;
  67         shape_name = "Rounded-corners";
  68         a = new Area();
  69         a.add(new Area(new Rectangle2D.Float(50, 0, 100, 150)));
  70         a.add(new Area(new Rectangle2D.Float(0, 50, 200, 50)));
  71         a.add(new Area(new Ellipse2D.Float(0, 0, 100, 100)));
  72         a.add(new Area(new Ellipse2D.Float(0, 50, 100, 100)));
  73         a.add(new Area(new Ellipse2D.Float(100, 0, 100, 100)));


 102 
 103             super.paint(g);
 104         }
 105     }
 106 
 107     class TestFrame extends Frame {
 108 
 109         @Override
 110         public void paint(Graphics g) {
 111 
 112             g.setColor(Color.WHITE);
 113             g.fillRect(0, 0, 200, 200);
 114 
 115             super.paint(g);
 116         }
 117     }
 118 
 119     public static void main(String[] args) throws Exception {
 120         robot = new Robot();
 121 
 122         for(int i = 0; i < 100; i++) {
 123             System.out.println("Attempt " + i);
 124             new ShapeNotSetSometimes().doTest();
 125         }
 126     }
 127 
 128     private void doTest() throws Exception {
 129         Point wls = backgroundFrame.getLocationOnScreen();
 130 
 131         robot.mouseMove(wls.x + 5, wls.y + 5);
 132         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
 133         robot.delay(10);
 134         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
 135         robot.delay(500);
 136 
 137         EventQueue.invokeAndWait(new Runnable() {
 138             public void run() {
 139                 window.requestFocus();
 140             }
 141         });
 142 
 143         robot.waitForIdle();
 144         try {
 145             Thread.sleep(300);
 146         } catch (InterruptedException e) {
 147             // ignore this one
 148         }
 149 
 150         // check transparency
 151         final int COUNT_TARGET = 10;
 152 
 153         // checking outside points only
 154         for(int i = COUNT_TARGET; i < COUNT_TARGET * 2; i++) {
 155             int x = pointsToCheck[i][0];
 156             int y = pointsToCheck[i][1];
 157             boolean inside = i < COUNT_TARGET;
 158             Color c = robot.getPixelColor(window.getX() + x, window.getY() + y);
 159             System.out.println("checking " + x + ", " + y + ", color = " + c);
 160             if (inside && BACKGROUND_COLOR.equals(c) || !inside && !BACKGROUND_COLOR.equals(c)) {
 161                 System.out.println("window.getX() = " + window.getX() + ", window.getY() = " + window.getY());


  29   @run main ShapeNotSetSometimes
  30 */
  31 
  32 
  33 import java.awt.*;
  34 import java.awt.event.InputEvent;
  35 import java.awt.geom.*;
  36 
  37 
  38 public class ShapeNotSetSometimes {
  39 
  40     private Frame backgroundFrame;
  41     private Frame window;
  42     private static final Color BACKGROUND_COLOR = Color.BLUE;
  43     private Shape shape;
  44     private int[][] pointsToCheck;
  45 
  46     private static Robot robot;
  47 
  48     public ShapeNotSetSometimes() throws Exception {
  49         EventQueue.invokeAndWait(this::initializeGUI);
  50         robot.waitForIdle();



  51     }
  52 
  53     private void initializeGUI() {
  54         backgroundFrame = new BackgroundFrame();
  55         backgroundFrame.setUndecorated(true);
  56         backgroundFrame.setSize(300, 300);
  57         backgroundFrame.setLocation(20, 400);
  58         backgroundFrame.setVisible(true);
  59 
  60         shape = null;
  61         String shape_name = null;
  62         Area a;
  63         GeneralPath gp;
  64         shape_name = "Rounded-corners";
  65         a = new Area();
  66         a.add(new Area(new Rectangle2D.Float(50, 0, 100, 150)));
  67         a.add(new Area(new Rectangle2D.Float(0, 50, 200, 50)));
  68         a.add(new Area(new Ellipse2D.Float(0, 0, 100, 100)));
  69         a.add(new Area(new Ellipse2D.Float(0, 50, 100, 100)));
  70         a.add(new Area(new Ellipse2D.Float(100, 0, 100, 100)));


  99 
 100             super.paint(g);
 101         }
 102     }
 103 
 104     class TestFrame extends Frame {
 105 
 106         @Override
 107         public void paint(Graphics g) {
 108 
 109             g.setColor(Color.WHITE);
 110             g.fillRect(0, 0, 200, 200);
 111 
 112             super.paint(g);
 113         }
 114     }
 115 
 116     public static void main(String[] args) throws Exception {
 117         robot = new Robot();
 118 
 119         for(int i = 0; i < 50; i++) {
 120             System.out.println("Attempt " + i);
 121             new ShapeNotSetSometimes().doTest();
 122         }
 123     }
 124 
 125     private void doTest() throws Exception {
 126         Point wls = backgroundFrame.getLocationOnScreen();
 127 
 128         robot.mouseMove(wls.x + 5, wls.y + 5);
 129         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
 130         robot.delay(10);
 131         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
 132         robot.delay(500);
 133 
 134         EventQueue.invokeAndWait(window::requestFocus);




 135 
 136         robot.waitForIdle();
 137         try {
 138             Thread.sleep(300);
 139         } catch (InterruptedException e) {
 140             // ignore this one
 141         }
 142 
 143         // check transparency
 144         final int COUNT_TARGET = 10;
 145 
 146         // checking outside points only
 147         for(int i = COUNT_TARGET; i < COUNT_TARGET * 2; i++) {
 148             int x = pointsToCheck[i][0];
 149             int y = pointsToCheck[i][1];
 150             boolean inside = i < COUNT_TARGET;
 151             Color c = robot.getPixelColor(window.getX() + x, window.getY() + y);
 152             System.out.println("checking " + x + ", " + y + ", color = " + c);
 153             if (inside && BACKGROUND_COLOR.equals(c) || !inside && !BACKGROUND_COLOR.equals(c)) {
 154                 System.out.println("window.getX() = " + window.getX() + ", window.getY() = " + window.getY());
< prev index next >