Package ui

Class GameUI

java.lang.Object
ui.GameUI
All Implemented Interfaces:
ActionListener, EventListener

public class GameUI extends Object implements ActionListener
creates the game UI JFrame containing a canvas (see class GamePanel)) for the levels to paint the games. Has a menu for loading, saving games and an about menu item. two buttons allow restarting the game or exit.
  • Field Details

  • Constructor Details

    • GameUI

      public GameUI(int sizeX, int sizeY)
      as typical for GUI classes this constructor creates all the components and adds them to the frame. It adds this instance as ActionListener for all components. See actionPerformed(ActionEvent) for details. It directly sets the frame visible as a final step.

      If you want to extend this GUI, create a subclass and add new elements in constructor. It is necessary to call Component.revalidate() on frame attribute after changing/adding components to panel or canvas, because the constructor here already sets visibility to true and renders the IFrame.

      Parameters:
      sizeX - pixel dimension wanted in x direction
      sizeY - pixel dimension wanted in y direction
  • Method Details

    • getCurrentKey

      public HashMap<Integer,Integer> getCurrentKey()
    • getKeyEvents

      public Stack<KeyEvent> getKeyEvents()
    • getMouseEvents

      public Stack<MouseEvent> getMouseEvents()
    • repaint

      public void repaint()
    • setPlayground

      public void setPlayground(Playground pg)
    • isPainting

      public boolean isPainting()
    • setPainting

      public void setPainting()
    • waitWhilePainting

      public void waitWhilePainting()
    • getNewAction

      public static int getNewAction()
    • resetAction

      public static void resetAction()
    • grabFocus

      public void grabFocus()
    • actionPerformed

      public void actionPerformed(ActionEvent ae)
      interface implementation of ActionListener to respond to GUI element actions. It sets the attribute of newAction which is read by GameLoop.runGame to check for GUI actions.
      Specified by:
      actionPerformed in interface ActionListener