Java by API/java.awt/Frame

Материал из Java эксперт
Перейти к: навигация, поиск

Frame.ICONIFIED

 

import java.awt.Frame;
public class Main {
  public static void main() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    frame.setVisible(true);
    iconify(frame);
  }
  public static void iconify(Frame frame) {
    int state = frame.getExtendedState();
    // Set the iconified bit
    state |= Frame.ICONIFIED;
    // Iconify the frame
    frame.setExtendedState(state);
  }
}





Frame.MAXIMIZED_BOTH

 
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) == 0 && (newState & Frame.ICONIFIED) != 0) {
          System.out.println("Frame was iconized");
        } else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0) {
          System.out.println("Frame was deiconized");
        }
        if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) {
          System.out.println("Frame was maximized");
        } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) {
          System.out.println("Frame was minimized");
        }
      }
    };
    frame.addWindowStateListener(listener);
    frame.setVisible(true);
  }
}