Package ui
Class GameUI
java.lang.Object
ui.GameUI
- All Implemented Interfaces:
ActionListener
,EventListener
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 Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionGameUI
(int sizeX, int sizeY) as typical for GUI classes this constructor creates all the components and adds them to the frame. -
Method Summary
Modifier and TypeMethodDescriptionvoid
interface implementation of ActionListener to respond to GUI element actions.static int
void
boolean
void
repaint()
static void
void
void
void
-
Field Details
-
ACTION_NEW
public static final int ACTION_NEW- See Also:
-
ACTION_LOAD
public static final int ACTION_LOAD- See Also:
-
ACTION_SAVE
public static final int ACTION_SAVE- See Also:
-
ACTION_RESET
public static final int ACTION_RESET- See Also:
-
ACTION_QUIT
public static final int ACTION_QUIT- See Also:
-
ACTION_BUTTON
public static final int ACTION_BUTTON- See Also:
-
ACTION_PAUSE
public static final int ACTION_PAUSE- See Also:
-
ACTION_ABOUT
public static final int ACTION_ABOUT- See Also:
-
-
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. SeeactionPerformed(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()
onframe
attribute after changing/adding components topanel
orcanvas
, because the constructor here already sets visibility to true and renders the IFrame.- Parameters:
sizeX
- pixel dimension wanted in x directionsizeY
- pixel dimension wanted in y direction
-
-
Method Details
-
getCurrentKey
-
getKeyEvents
-
getMouseEvents
-
repaint
public void repaint() -
setPlayground
-
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
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 interfaceActionListener
-