1 /*
2  * Copyright (c) 2004, 2014, 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 javax.swing.*;
25 import java.awt.*;
26 import java.awt.event.WindowAdapter;
27 import java.awt.event.WindowEvent;
28 
29 /*
30  * @author Aruna Samji
31  */
32 
33 public class GUIUndFrame extends Frame {
34 
35     JFrame jframe1, jframe2, jframe3;
36     Component comp;
37     JButton jbutton1, jbutton2, jbutton3, jbutton4;
38     JTextArea jtextarea;
39 
40     volatile boolean win_act, win_deact, win_ico, win_deico, win_close;
41 
GUIUndFrame()42     public GUIUndFrame() {
43         //GUI for UndJFrameProperties
44         jframe1 = new JFrame();
45         jframe1.getContentPane().setLayout(new FlowLayout());
46         jframe1.setSize(500,255);
47         jframe1.setUndecorated(true);
48         jframe1.getContentPane().setBackground(Color.red);
49 
50         jframe1.addWindowListener( new WindowAdapter() {
51             public void windowActivated(WindowEvent e){
52                 comp = null;
53                 comp = e.getComponent();
54                 if (e.getComponent() == jframe1)
55                     win_act = true;
56             }
57 
58             public void windowDeactivated(WindowEvent e){
59                 win_deact = true;
60             }
61         });
62 
63 
64         jbutton1 = new JButton("Hide me");
65         jbutton1.addActionListener(e -> jframe1.setVisible(false));
66 
67 
68         //Create a normal decorated frame to test all the relevant assertions
69         jframe2 = new JFrame();
70         jframe2.getContentPane().setLayout(new FlowLayout());
71         jframe2.setLocation(0,270);
72         jframe2.setSize(500,255);
73         jframe2.getContentPane().setBackground(Color.blue);
74         jbutton2 = new JButton("Show hiddenJFrame");
75         jbutton2.addActionListener(e -> jframe1.setVisible(true));
76 
77 
78         //GUI for UndFrameIconifyRepaint
79         jframe3 = new JFrame();
80         jframe3.getContentPane().setLayout(new FlowLayout());
81         jframe3.setSize(500,255);
82         jframe3.getContentPane().setBackground(Color.green);
83         jframe3.setUndecorated(true);
84         jframe3.addWindowListener( new WindowAdapter() {
85             public void windowActivated(WindowEvent e) {
86                 comp = null;
87                 comp = e.getComponent();
88                 if(e.getComponent() == jframe3){
89                     win_act=true;
90 
91                 }
92             }
93             public void windowIconified(WindowEvent e){ win_ico = true; }
94             public void windowDeiconified(WindowEvent e){ win_deico = true; }
95             public void windowDeactivated(WindowEvent e){ win_deact = true; }
96             public void windowClosed(WindowEvent e){ win_close = true; }
97         });
98 
99         jbutton3 = new JButton("Minimize me");
100         jbutton3.addActionListener(e -> jframe3.setState(Frame.ICONIFIED));
101         jbutton4 = new JButton("Maximize me");
102         jbutton4.addActionListener(e -> {
103             if (Toolkit.getDefaultToolkit().isFrameStateSupported
104                     (Frame.MAXIMIZED_BOTH)) {
105                 jframe3.setExtendedState(Frame.MAXIMIZED_BOTH);
106             }
107         });
108 
109         jtextarea = new JTextArea("Textarea");
110     }
111 }
112