|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Canvas
JTP.Screen
public class Screen
Controls all other game components and performs double-buffered rendering.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Canvas |
---|
Canvas.AccessibleAWTCanvas |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
Screen(double scaleFactor)
Creates a new Screen instance. |
Method Summary | |
---|---|
protected boolean |
automaticMovesLeft()
Used by KeyHandler class to decide whether another move
should be executed. |
protected Images |
getImageData()
Provides access to global image resources |
protected KeyHandler |
getKeyHandler()
Allows parent class (JFrame) to forward key events to handler of this class. |
Point |
getMousePosition()
Overloaded from Component class. |
Dimension |
getSize()
Returns size of whole (scaled) game screen. |
protected void |
handleDeactivation()
If window loses focus do not preserve mouse/keyboard status |
void |
keyPressedGame(int keyCode1,
int keyCode2,
long eventTime)
Handler for all keyboard events whilst in-game. |
void |
keyPressedNormal(KeyEvent e)
Handler for all keyboard events (except in-game). |
void |
keyReleased(KeyEvent e)
Handler for key releases. |
void |
keyTyped(KeyEvent e)
Handler for highscore name input. |
void |
mouseClicked(MouseEvent e)
Not used (defined by MouseInputListener ) |
void |
mouseDragged(MouseEvent e)
Handles mouse movement while key is depressed. |
void |
mouseEntered(MouseEvent e)
Not used (defined by MouseInputListener ) |
void |
mouseExited(MouseEvent e)
Prevents button or grid tile to be active when mouse moved off screen |
void |
mouseMoved(MouseEvent e)
Handles mouse movement events. |
void |
mousePressed(MouseEvent e)
Handles mouse-down events. |
void |
mouseReleased(MouseEvent e)
Handles mouse click events (once button has been released) |
void |
paint(Graphics g)
Draws screen updated (requirement by Canvas class) |
protected void |
returnToMenu()
Used by GameTimer to return focus to menu when time runs out. |
boolean |
scaled()
Returns whether the game is scaled up/down. |
void |
start(SplashControl splash)
Initialises various game components. |
void |
update(Graphics g)
Draws screen update, automatically choosing right component to render. |
protected void |
updateScreen()
Forces screen update. |
Methods inherited from class java.awt.Canvas |
---|
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Screen(double scaleFactor) throws NumberFormatException
Screen
instance.
scaleFactor
- how much to scale output by (a value of 1
results in no scaling)
NumberFormatException
- if scaleFactor <= 0
Method Detail |
---|
public Dimension getSize()
getSize
in class Component
public void update(Graphics g)
update
in class Canvas
g
- graphics context for renderingpublic void paint(Graphics g)
Canvas
class)
paint
in class Canvas
protected void updateScreen()
protected void handleDeactivation()
protected Images getImageData()
public boolean scaled()
true
if the game is being scaled.public void mouseMoved(MouseEvent e)
mouseMoved
in interface MouseMotionListener
e
- the incoming mouse eventpublic void mouseReleased(MouseEvent e)
mouseReleased
in interface MouseListener
e
- the incoming mouse event.public void mousePressed(MouseEvent e)
mousePressed
in interface MouseListener
e
- the incoming mouse event.public void mouseDragged(MouseEvent e)
mouseMoved
method.
mouseDragged
in interface MouseMotionListener
e
- the incoming mouse event.public void mouseExited(MouseEvent e)
mouseExited
in interface MouseListener
e
- the incoming mouse event.public void keyReleased(KeyEvent e)
e
- the incoming key release event.public void keyTyped(KeyEvent e)
e
- the incoming key press event.public void keyPressedNormal(KeyEvent e)
KeyHandler
.
e
- the incoming key press event.public void keyPressedGame(int keyCode1, int keyCode2, long eventTime)
keyCode1
- player 1 key or control key (e.g. F9)keyCode2
- player 2 keyeventTime
- so that really old keyboard events can be discardedpublic void start(SplashControl splash) throws IOException
splash
- instance of SplashControl
in use.
IOException
- if any of the (non-optional) game resources could not
be loaded.protected boolean automaticMovesLeft()
KeyHandler
class to decide whether another move
should be executed.
protected void returnToMenu()
GameTimer
to return focus to menu when time runs out.
protected KeyHandler getKeyHandler()
public Point getMousePosition() throws HeadlessException
Component
class. This method will not return
null
but instead a Point
instance with
coordinates [-1,-1]. (In line with what e.g. mouseExited
returns in the case where the mouse has left the screen.)
getMousePosition
in class Component
Canvas
or
[-1,-1] if it is not over this component.
HeadlessException
- if GraphicsEnvironment.isHeadless() returns truepublic void mouseClicked(MouseEvent e)
MouseInputListener
)
mouseClicked
in interface MouseListener
public void mouseEntered(MouseEvent e)
MouseInputListener
)
mouseEntered
in interface MouseListener
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |