|
1 | 1 | /* |
2 | | - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 23 |
|
24 | | -/* |
25 | | - * @test |
26 | | - * @bug 6348456 |
27 | | - * @summary Tests model changing |
28 | | - * @author Sergey Malenkov |
29 | | - * @run applet/manual=yesno Test6348456.html |
30 | | - */ |
31 | | - |
32 | 24 | import java.awt.BorderLayout; |
33 | 25 | import java.awt.Color; |
34 | 26 | import java.awt.event.ActionEvent; |
35 | 27 | import java.awt.event.ActionListener; |
36 | | -import javax.swing.JApplet; |
37 | 28 | import javax.swing.JButton; |
38 | 29 | import javax.swing.JColorChooser; |
| 30 | +import javax.swing.JFrame; |
39 | 31 | import javax.swing.colorchooser.DefaultColorSelectionModel; |
40 | 32 |
|
41 | | -public final class Test6348456 extends JApplet implements ActionListener { |
| 33 | +/* |
| 34 | + * @test |
| 35 | + * @bug 6348456 |
| 36 | + * @library /java/awt/regtesthelpers |
| 37 | + * @build PassFailJFrame |
| 38 | + * @summary Tests model changing |
| 39 | + * @run main/manual Test6348456 |
| 40 | + */ |
42 | 41 |
|
43 | | - private static final DefaultColorSelectionModel WHITE = new DefaultColorSelectionModel(Color.WHITE); |
44 | | - private static final DefaultColorSelectionModel BLACK = new DefaultColorSelectionModel(Color.BLACK); |
| 42 | +public final class Test6348456 { |
45 | 43 |
|
46 | | - private JColorChooser chooser; |
| 44 | + private static final DefaultColorSelectionModel WHITE = |
| 45 | + new DefaultColorSelectionModel(Color.WHITE); |
| 46 | + private static final DefaultColorSelectionModel BLACK = |
| 47 | + new DefaultColorSelectionModel(Color.BLACK); |
47 | 48 |
|
48 | | - @Override |
49 | | - public void init() { |
50 | | - JButton button = new JButton("Swap models"); |
51 | | - button.addActionListener(this); |
| 49 | + private static JColorChooser chooser; |
52 | 50 |
|
53 | | - this.chooser = new JColorChooser(Color.RED); |
54 | | - this.chooser.setSelectionModel(WHITE); |
| 51 | + public static void main(String[] args) throws Exception { |
| 52 | + String instructions = "When test starts, you'll see that the preview is white.\n" + |
| 53 | + "When you swap models, you'll see that the preview color is changed.\n" + |
| 54 | + "Click pass if so, otherwise fail."; |
55 | 55 |
|
56 | | - add(BorderLayout.NORTH, button); |
57 | | - add(BorderLayout.CENTER, this.chooser); |
| 56 | + PassFailJFrame.builder() |
| 57 | + .title("Test6348456") |
| 58 | + .instructions(instructions) |
| 59 | + .rows(5) |
| 60 | + .columns(40) |
| 61 | + .testTimeOut(10) |
| 62 | + .testUI(Test6348456::test) |
| 63 | + .build() |
| 64 | + .awaitAndCheck(); |
58 | 65 | } |
59 | 66 |
|
60 | | - public void actionPerformed(ActionEvent event){ |
61 | | - this.chooser.setSelectionModel(this.chooser.getSelectionModel() == BLACK ? WHITE : BLACK); |
| 67 | + public static JFrame test() { |
| 68 | + JFrame frame = new JFrame("JColor Swap Models Test"); |
| 69 | + JButton button = new JButton("Swap models"); |
| 70 | + button.addActionListener(new ActionListener() { |
| 71 | + @Override |
| 72 | + public void actionPerformed(ActionEvent event) { |
| 73 | + chooser.setSelectionModel(chooser.getSelectionModel() == BLACK ? WHITE : BLACK); |
| 74 | + |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + chooser = new JColorChooser(Color.RED); |
| 79 | + chooser.setSelectionModel(WHITE); |
| 80 | + |
| 81 | + frame.add(BorderLayout.NORTH, button); |
| 82 | + frame.add(BorderLayout.CENTER, chooser); |
| 83 | + frame.pack(); |
| 84 | + |
| 85 | + return frame; |
62 | 86 | } |
63 | 87 | } |
0 commit comments