Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSpinner/SpinnerTest.java
41149 views
1
/*
2
* Copyright (c) 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
*/
23
24
/* @test
25
@bug 5078989
26
@key headful
27
@summary Verifies Null Pointer exception is not thrown in SpinnerListMode
28
@run main SpinnerTest
29
*/
30
import javax.swing.JFrame;
31
import javax.swing.JLabel;
32
import javax.swing.JPanel;
33
import javax.swing.JSpinner;
34
import javax.swing.SpinnerListModel;
35
import javax.swing.SwingUtilities;
36
import java.awt.event.KeyEvent;
37
import java.awt.Point;
38
import java.awt.Robot;
39
40
public class SpinnerTest
41
{
42
private static JFrame frame;
43
private static JSpinner spinner;
44
45
public static void main(String[] args) throws Exception {
46
Robot robot = new Robot();
47
robot.setAutoDelay(100);
48
try {
49
SwingUtilities.invokeAndWait(() -> {
50
//Create and set up the window.
51
frame = new JFrame("SpinnerDemo");
52
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53
54
JPanel panel = new JPanel();
55
String[] values = {"Month: ", "Year: ", null, "Date", "Sent"};
56
57
SpinnerListModel listModel = new SpinnerListModel(values);
58
59
JLabel l = new JLabel("Spinner");
60
panel.add(l);
61
62
spinner = new JSpinner(listModel);
63
l.setLabelFor(spinner);
64
panel.add(spinner);
65
66
panel.setOpaque(true); //content panes must be opaque
67
frame.setContentPane(panel);
68
69
//Display the window.
70
frame.pack();
71
frame.setVisible(true);
72
frame.setLocationRelativeTo(null);
73
});
74
robot.waitForIdle();
75
robot.delay(1000);
76
Point loc = spinner.getLocationOnScreen();
77
78
robot.mouseMove(loc.x, loc.y);
79
robot.keyPress(KeyEvent.VK_SPACE);
80
robot.keyRelease(KeyEvent.VK_SPACE);
81
82
} finally {
83
if (frame != null) {
84
SwingUtilities.invokeAndWait(() -> frame.dispose());
85
}
86
}
87
}
88
}
89
90