class ResizeComponentListener extends ComponentAdapter {

  private static final String BOUNDS_PROPERTY_NAME = "frame.bounds";

  static void attachToWindow(JFrame frame) {
    frame.addComponentListener(new ResizeComponentListener(frame));
  }

  static void setBoundsProperty(JFrame frame, Rectangle bounds) {
    frame.getRootPane().putClientProperty(BOUNDS_PROPERTY_NAME, bounds);
  }

  static Rectangle getBoundsProperty(JFrame frame) {
    return (Rectangle) frame.getRootPane().getClientProperty(BOUNDS_PROPERTY_NAME);
  }

  private final JFrame frame;

  private ResizeComponentListener(JFrame frame) {
    this.frame = frame;
  }

  @Override
  public void componentResized(ComponentEvent e) {
    saveBounds();
  }

  @Override
  public void componentMoved(ComponentEvent e) {
    saveBounds();
  }

  private void saveBounds() {<FILL_FUNCTION_BODY>}

}

    if ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) {
      Rectangle bounds = frame.getBounds();
      frame.getRootPane().putClientProperty(BOUNDS_PROPERTY_NAME, bounds);
    }
  
<methods>public void componentHidden(java.awt.event.ComponentEvent) ,public void componentMoved(java.awt.event.ComponentEvent) ,public void componentResized(java.awt.event.ComponentEvent) ,public void componentShown(java.awt.event.ComponentEvent) <variables>