/** * Displays the window, allowing the MiniGame application to start accepting user input and allow * the user to actually play the game. */ public void startGame() { // DISPLAY THE WINDOW window.setVisible(true); // LET'S NOW CORRECT THE WINDOW SIZE. THE REASON WE DO THIS // IS BECAUSE WE'RE USING null LAYOUT MANAGER, SO WE NEED TO // SIZE STUFF OURSELVES, AND WE WANT THE WINDOW SIZE TO BE THE // SIZE OF THE CANVAS + THE BORDER OF THE WINDOW, WHICH WOULD // INCLUDE THE TITLE BAR. THIS IS CALLED THE WINDOW'S INSETS Insets insets = window.getInsets(); int correctedWidth = data.getGameWidth() + insets.left + insets.right; int correctedHeight = data.getGameHeight() + insets.top + insets.bottom; window.setSize(correctedWidth, correctedHeight); }
/** * This should initialize and setup all GUI components. Note that it will invoke the * custom-implemented initGUIControls method, which the game developer must provide to setup * buttons. */ private void initGUI() { // INITIALIZE OUR GUI DATA STRUCTURES guiButtons = new TreeMap(); guiDecor = new TreeMap(); guiDialogs = new TreeMap(); // WE'LL LAYOUT EVERYTHING USING PIXEL COORDINATES window.setLayout(null); // GUI CONTROLS ARE SETUP BY THE GAME DEVELOPER // USING THIS FRAMEWORK initGUIControls(); // ULTIMATELY, EVERYTHING SHOULD BE INSIDE THE CANVAS window.add(canvas); canvas.setBounds(0, 0, data.getGameWidth(), data.getGameHeight()); }