Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ java/awt/Focus/6981400/Test1.java 8029675 windows-all,macosx-all
java/awt/Focus/6981400/Test3.java 8173264 generic-all
java/awt/event/KeyEvent/ExtendedKeyCode/ExtendedKeyCodeTest.java 8169476 windows-all,macosx-all
java/awt/event/KeyEvent/KeyChar/KeyCharTest.java 8169474,8224055 macosx-all,windows-all
java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_3.java 6854300 generic-all
java/awt/event/KeyEvent/ExtendedModifiersTest/ExtendedModifiersTest.java 8129778 generic-all
java/awt/event/KeyEvent/KeyMaskTest/KeyMaskTest.java 8129778 generic-all
java/awt/event/MouseEvent/MouseButtonsAndKeyMasksTest/MouseButtonsAndKeyMasksTest.java 8129778 generic-all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, 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
Expand Down Expand Up @@ -49,44 +49,70 @@
" move the pointer between B to C.",
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;

import test.java.awt.regtesthelpers.Util;
import javax.swing.*;

import javax.swing.JButton;
import javax.swing.JFrame;

public class SpuriousExitEnter_3 {
static JFrame frame = new JFrame("SpuriousExitEnter_3_LW");
static JButton jbutton = new JButton("jbutton");
static Frame frame1 = new Frame("SpuriousExitEnter_3_HW");
static Button button1 = new Button("button");

static EnterExitAdapter frameAdapter;
static EnterExitAdapter buttonAdapter;
static Robot r = Util.createRobot();

public static void testCase(Window w, Component comp) {
frameAdapter = new EnterExitAdapter(w);
buttonAdapter = new EnterExitAdapter(comp);

w.addMouseListener(frameAdapter);
comp.addMouseListener(buttonAdapter);

w.setSize(200, 200);
w.add(comp, BorderLayout.NORTH);
w.setLocationRelativeTo(null);
w.setVisible(true);

Point centerA = new Point(comp.getLocationOnScreen().x + comp.getWidth() / 2,
comp.getLocationOnScreen().y + comp.getHeight() / 2);
Point centerB = new Point(w.getLocationOnScreen().x + w.getWidth() / 2,
w.getLocationOnScreen().y + w.getHeight() / 2);
//for moving from A outside: don't cross the A area. Move straight to the right.
Point centerC_1 = new Point(w.getLocationOnScreen().x + w.getWidth() + 20, //go right off the border
comp.getLocationOnScreen().y + comp.getHeight() / 2); //don't cross the A area!

//for moving from B outside: don't cross the B area. Move straight to the bottom.
Point centerC_2 = new Point(w.getLocationOnScreen().x + w.getWidth() / 2,
w.getLocationOnScreen().y + w.getHeight() + 20); //go below the bottom border
static JFrame frame;
static JButton jbutton;

static Frame frame1;
static Button button1;

static final Robot r = Util.createRobot();

static volatile EnterExitAdapter frameAdapter;
static volatile EnterExitAdapter buttonAdapter;
static volatile Point centerA;
static volatile Point centerB;
static volatile Point centerC_1 ;
static volatile Point centerC_2;

public static void testCase(Window w, Component comp) throws InterruptedException, InvocationTargetException {
EventQueue.invokeAndWait(()-> {
frameAdapter = new EnterExitAdapter(w);
buttonAdapter = new EnterExitAdapter(comp);

w.addMouseListener(frameAdapter);
comp.addMouseListener(buttonAdapter);

w.setSize(200, 200);
w.add(comp, BorderLayout.NORTH);
w.setLocationRelativeTo(null);
w.setVisible(true);
});

r.waitForIdle();
r.delay(1000);

EventQueue.invokeAndWait(()-> {
centerA = new Point(comp.getLocationOnScreen().x + comp.getWidth() / 2,
comp.getLocationOnScreen().y + comp.getHeight() / 2);
centerB = new Point(w.getLocationOnScreen().x + w.getWidth() / 2,
w.getLocationOnScreen().y + w.getHeight() / 2);
//for moving from A outside: don't cross the A area. Move straight to the right.
centerC_1 = new Point(w.getLocationOnScreen().x + w.getWidth() + 20, //go right off the border
comp.getLocationOnScreen().y + comp.getHeight() / 2); //don't cross the A area!

//for moving from B outside: don't cross the B area. Move straight to the bottom.
centerC_2 = new Point(w.getLocationOnScreen().x + w.getWidth() / 2,
w.getLocationOnScreen().y + w.getHeight() + 20); //go below the bottom border
});

//A and B areas
Util.pointOnComp(comp, r);
Util.waitForIdle(r);
Expand Down Expand Up @@ -118,12 +144,23 @@ public static void testCase(Window w, Component comp) {
Util.waitForIdle(r);
}

public static void main(String []s)
{
//LW case:
testCase(frame, jbutton);
//HW case
testCase(frame1, button1);

public static void main(String []s) throws InterruptedException, InvocationTargetException {
EventQueue.invokeAndWait(() -> {
frame = new JFrame("SpuriousExitEnter_3_LW");
jbutton = new JButton("jbutton");

frame1 = new Frame("SpuriousExitEnter_3_HW");
button1 = new Button("button");
});

try {
testCase(frame, jbutton); //LW case
testCase(frame1, button1); //HW case
} finally {
EventQueue.invokeLater(frame::dispose);
EventQueue.invokeLater(frame1::dispose);
}
}

private static void moveBetween(Robot r, Point first, Point second) {
Expand All @@ -150,9 +187,9 @@ private static void checkEvents(EnterExitAdapter adapter, int entered, int exite


class EnterExitAdapter extends MouseAdapter {
private Component target;
private int enteredEventCount = 0;
private int exitedEventCount = 0;
private final Component target;
private volatile int enteredEventCount = 0;
private volatile int exitedEventCount = 0;

public EnterExitAdapter(Component target) {
this.target = target;
Expand All @@ -170,7 +207,7 @@ public int getExitedEventCount(){
}

public void zeroCounters(){
System.out.println("Zeroeing on " +target.getClass().getName());
System.out.println("Zeroing on " +target.getClass().getName());
enteredEventCount = 0;
exitedEventCount = 0;
}
Expand Down