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 java.awt.*;
  25 import java.awt.event.WindowAdapter;
  26 import java.awt.event.WindowEvent;
  27 
  28 /*
  29  * @author Aruna Samji
  30  */
  31 
  32 public class GUIZoomFrame extends Frame {
  33 
  34     Frame frame1, frame2;
  35     Button button;
  36     Button icon, maximize;
  37     TextArea textarea;
  38     volatile boolean maxHor, maxVer, maxBoth, normal, iconify;
  39 
  40     public GUIZoomFrame() {
  41         //GUI for ZoomFrameChangeState
  42         frame1 = new Frame("ZoomFrameChangeState");
  43         frame1.setBackground(Color.red);
  44         frame1.setSize(500,270);
  45         icon = new Button("Iconify me");
  46         maximize = new Button("Maximize me");
  47         icon.setBounds(20, 100, 80, 60);
  48         maximize.setBounds(20, 100, 80, 60);
  49 
  50         //GUI for ZoomFrameRepaint
  51         frame2 = new Frame("ZoomFrameRepaint");
  52         frame2.setBackground(Color.red);
  53         frame2.setSize(500,270);
  54         frame2.setLayout(null);
  55         button = new Button("TestButton");
  56         textarea = new TextArea("TextArea");
  57         button.setBounds(20, 100, 80, 60);
  58         textarea.setBounds(120, 100, 80, 60);
  59 
  60         //Listeners for ZoomFrameChangeState
  61         frame1.addWindowStateListener( new WindowAdapter() {
  62             public void windowStateChanged(WindowEvent e) {
  63                 if (e.getNewState() == Frame.MAXIMIZED_BOTH)
  64                     maxBoth=true;
  65 
  66                 if (e.getNewState() == Frame.NORMAL)
  67                     normal=true;
  68 
  69                 if (e.getNewState() == Frame.ICONIFIED)
  70                     iconify=true;
  71 
  72                 if (e.getNewState() == Frame.MAXIMIZED_HORIZ)
  73                     maxHor=true;
  74 
  75                 if (e.getNewState() == Frame.MAXIMIZED_VERT)
  76                     maxVer=true;
  77             }
  78 
  79         });
  80 
  81         icon.addActionListener(e -> frame1.setExtendedState(Frame.ICONIFIED));
  82 
  83         maximize.addActionListener( e -> {
  84             if (Toolkit.getDefaultToolkit().isFrameStateSupported
  85                 (Frame.MAXIMIZED_BOTH)){
  86                 //Maximising the Frame fully
  87                 frame1.setExtendedState(Frame.MAXIMIZED_BOTH);
  88             }
  89         });
  90 
  91         //Listeners for ZoomFrameRepaint
  92         frame2.addWindowStateListener( new WindowAdapter() {
  93             public void windowStateChanged(WindowEvent e) {
  94                 if (e.getNewState() == Frame.MAXIMIZED_BOTH)
  95                     maxBoth = true;
  96 
  97                 if (e.getNewState() == Frame.NORMAL)
  98                     normal = true;
  99             }
 100         });
 101     }
 102 }