If the user changes the window’s position or size, they might prefer that the window open to the same position and size the next time they run the program. So save the window’s position and size when the window is closed, and open the window to the saved position and size when the window is opened.

Saving the window size and position when the window is closed

Create the instance variables needed to save the window’s size and position.

  1. Add a new private final static string instance variable called SETTINGS_FILE, set to “wordBuilderSettings.txt”.
  2. Add private integer instance variables called windowX, windowY, windowW, and windowH to hold the window’s x and y position, and width and height. Their initial values should all be -1.
  3. Add a private integer instance variable called windowState, with an initial value of JFrame.Normal.
    ...
 
  private static final Font BIGFONT = new Font(Font.DIALOG, Font.BOLD, 30);
  ___________ SETTINGS_FILE = ___________;
  
  ___________ windowX = _______;
  ___________ windowY = _______;
  ___________ windowW = _______;
  ___________ windowH = _______;
  ___________ windowState = _______;
  
    ...

Get hands-on with 1200+ tech skills courses.