Determining When a Frame or Window Is Iconized or Maximized : JFrame States « Swing « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Swing » JFrame States 
14.81.6.Determining When a Frame or Window Is Iconized or MaximizedPrevious/Next
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;

public class Main {
  public static void main() {

    Frame frame = new Frame();

    WindowStateListener listener = new WindowAdapter() {
      public void windowStateChanged(WindowEvent evt) {
        int oldState = evt.getOldState();
        int newState = evt.getNewState();

        if ((oldState & Frame.ICONIFIED== && (newState & Frame.ICONIFIED!= 0) {
          System.out.println("Frame was iconized");
        else if ((oldState & Frame.ICONIFIED!= && (newState & Frame.ICONIFIED== 0) {
          System.out.println("Frame was deiconized");
        }

        if ((oldState & Frame.MAXIMIZED_BOTH== && (newState & Frame.MAXIMIZED_BOTH!= 0) {
          System.out.println("Frame was maximized");
        else if ((oldState & Frame.MAXIMIZED_BOTH!= && (newState & Frame.MAXIMIZED_BOTH== 0) {
          System.out.println("Frame was minimized");
        }
      }
    };

    frame.addWindowStateListener(listener);
    frame.setVisible(true);
  }
}
14.81.JFrame States
14.81.1.Setting the Bounds for a Maximized Frame
14.81.2.Iconifies a frame; the maximized bits are not affected.
14.81.3.Deiconifies a frame; the maximized bits are not affected.
14.81.4.Maximizes a frame; the iconified bit is not affected
14.81.5.Determining When a Frame or Window Is Opened or Closed
14.81.6.Determining When a Frame or Window Is Iconized or Maximized
14.81.7.Determining When a Component Has Been Made Visible, Moved, or Resized
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.