/* GameFrame class establishes the frame (window) for the game It is a child of JFrame because JFrame manages frames Runs the constructor in GamePanel class */ import java.awt.*; import java.io.IOException; import javax.swing.*; public class GameFrame extends JFrame{ MenuPanel menu; GamePanel game; boolean startGame = false; public GameFrame(){ menu = new MenuPanel(); while (!startGame) { startGame = menu.hasButtonClicked(); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } menu.setVisible(false); // hide menu when game has launched try { game = new GamePanel(); //run GamePanel constructor } catch (IOException | SpriteException e) { // TODO: handle IO errors gracefully // exceptions are raised when tiles are not found or are of incorrect dimensions menu.setVisible(true); menu.launchGame.setText("Invalid sprites error"); } this.add(game); this.setTitle("GUI is cool!"); //set title for frame this.setResizable(false); //frame can't change size this.setBackground(Color.white); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //X button will stop program execution this.pack();//makes components fit in window - don't need to set JFrame size, as it will adjust accordingly this.setVisible(true); //makes window visible to user this.setLocationRelativeTo(null);//set window in middle of screen } }