1 /*
2 * Copyright (c) 2012, 2016, 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 */
60
61 Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
62 public void eventDispatched(AWTEvent e) {
63 System.out.println(e);
64 if (e instanceof sun.awt.UngrabEvent) {
65 ungrabbed = true;
66 }
67 }
68 }, sun.awt.SunToolkit.GRAB_EVENT_MASK);
69
70 f = new Frame("Frame");
71 f.setBounds(0, 0, 300, 300);
72 f.addMouseListener(new MouseAdapter() {
73 public void mousePressed(MouseEvent e) {
74 System.out.println(e);
75 framePressed = true;
76 }
77 });
78
79 f1 = new Frame("OtherFrame");
80 f1.setBounds(700, 100, 200, 200);
81
82 w = new Window(f);
83 w.setLayout(new FlowLayout());
84 b = new Button("Press");
85 b.addActionListener(new ActionListener() {
86 public void actionPerformed(ActionEvent e) {
87 System.out.println(e);
88 buttonPressed = true;
89 }
90 });
91 w.add(b);
92 w.setBounds(400, 100, 200, 200);
93 w.setBackground(Color.blue);
94 w.addMouseListener(new MouseAdapter() {
95 public void mousePressed(MouseEvent e) {
96 System.out.println(e);
97 windowPressed = true;
98 }
99 });
100
101 f.setVisible(true);
102 w.setVisible(true);
103
104 frame = new Frame();
105 window1 = new Window(frame);
106 window1.setBounds(0, 0, 100, 100);
107 window1.setBackground(Color.blue);
108
109 window2 = new Window(window1);
110 window2.setBounds(0, 0, 50, 50);
111 window2.setBackground(Color.green);
112
113 tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
114
115 try {
116 robot = new Robot();
117 } catch (AWTException ex) {
118 throw new RuntimeException(ex);
119 }
120
121 Util.waitForIdle(robot);
122
123 test();
124 }
125
126 public static void test() {
127 tk.grab(w);
128
129 // 1. Check that button press doesn't cause ungrab
130 Util.clickOnComp(b, robot);
|
1 /*
2 * Copyright (c) 2012, 2020, 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 */
60
61 Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
62 public void eventDispatched(AWTEvent e) {
63 System.out.println(e);
64 if (e instanceof sun.awt.UngrabEvent) {
65 ungrabbed = true;
66 }
67 }
68 }, sun.awt.SunToolkit.GRAB_EVENT_MASK);
69
70 f = new Frame("Frame");
71 f.setBounds(0, 0, 300, 300);
72 f.addMouseListener(new MouseAdapter() {
73 public void mousePressed(MouseEvent e) {
74 System.out.println(e);
75 framePressed = true;
76 }
77 });
78
79 f1 = new Frame("OtherFrame");
80 f1.setBounds(700, 100, 300, 300);
81
82 w = new Window(f);
83 w.setLayout(new FlowLayout());
84 b = new Button("Press");
85 b.addActionListener(new ActionListener() {
86 public void actionPerformed(ActionEvent e) {
87 System.out.println(e);
88 buttonPressed = true;
89 }
90 });
91 w.add(b);
92 w.setBounds(400, 100, 300, 300);
93 w.setBackground(Color.blue);
94 w.addMouseListener(new MouseAdapter() {
95 public void mousePressed(MouseEvent e) {
96 System.out.println(e);
97 windowPressed = true;
98 }
99 });
100
101 f.setVisible(true);
102 w.setVisible(true);
103
104 frame = new Frame();
105 window1 = new Window(frame);
106 window1.setSize(200, 200);
107 window1.setLocationRelativeTo(null);
108 window1.setBackground(Color.blue);
109
110 window2 = new Window(window1);
111 window2.setSize(100, 100);
112 window2.setLocationRelativeTo(null);
113 window2.setBackground(Color.green);
114
115 tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
116
117 try {
118 robot = new Robot();
119 } catch (AWTException ex) {
120 throw new RuntimeException(ex);
121 }
122
123 Util.waitForIdle(robot);
124
125 test();
126 }
127
128 public static void test() {
129 tk.grab(w);
130
131 // 1. Check that button press doesn't cause ungrab
132 Util.clickOnComp(b, robot);
|