Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/JAWT/MyMacCanvas.java
41149 views
1
/*
2
* Copyright (c) 2021, 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
import java.awt.*;
25
import java.awt.event.*;
26
import javax.swing.*;
27
28
public class MyMacCanvas extends Canvas {
29
30
static {
31
try {
32
System.loadLibrary("mylib");
33
} catch (Throwable t) {
34
System.out.println("Test failed!!");
35
t.printStackTrace();
36
System.exit(1);
37
}
38
}
39
40
public void addNotify() {
41
super.addNotify();
42
addNativeCoreAnimationLayer();
43
}
44
45
public native void addNativeCoreAnimationLayer();
46
47
static JAWTFrame f;
48
public static void main(String[] args) {
49
try {
50
Robot robot = new Robot();
51
EventQueue.invokeLater(new Runnable() {
52
public void run() {
53
f = new JAWTFrame("JAWTExample");
54
f.setBackground(Color.white);
55
f.setLayout(new BorderLayout(10, 20));
56
f.setLocation(50, 50);
57
((JComponent) f.getContentPane()).setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.cyan));
58
f.addNotify();
59
f.pack();
60
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61
f.setVisible(true);
62
}
63
});
64
robot.delay(5000);
65
Color col1 = new Color(0, 0, 0);
66
Color col2 = robot.getPixelColor(f.getX()+50, f.getY()+50);
67
if (col1.equals(col2)) {
68
System.out.println("Test passed!");
69
} else {
70
System.out.println("col1 " + col1 + " col2 " + col2);
71
throw new RuntimeException("Color of JAWT canvas is wrong or " +
72
"it was not rendered. " + "Check that other windows " +
73
"do not block the test frame.");
74
}
75
System.exit(0);
76
} catch (Throwable t) {
77
System.out.println("Test failed!");
78
t.printStackTrace();
79
System.exit(1);
80
}
81
}
82
83
private static class JAWTFrame extends JFrame {
84
public JAWTFrame(final String title) {
85
super(title);
86
}
87
88
public void addNotify() {
89
super.addNotify(); // ensures native component hierarchy is setup
90
91
final Component layerBackedCanvas = new MyMacCanvas();
92
layerBackedCanvas.setPreferredSize(new Dimension(400, 200));
93
add(layerBackedCanvas, BorderLayout.CENTER);
94
95
invalidate();
96
}
97
}
98
}
99
100