nu.dll.pong
Class PongPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--nu.dll.pong.PongPanel
All Implemented Interfaces:
java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class PongPanel
extends java.awt.Component
implements java.awt.image.ImageObserver, java.awt.event.MouseMotionListener, java.awt.event.MouseListener, java.awt.event.KeyListener

The component that is the game. Creates at least two threads: one for ball animation (class BallMoverThread), which takes care of ball movement, collisions and some other animation details. The other is the ScoreAnimatorThread class, which sole purpose is to nicely increment the displayed score on screen. These threads (and the game) are started upon invokation of the start() method.

See Also:
Main-class for running the game stand-alone, Serialized Form

Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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
PongPanel()
          Creates a Pong component using the default values and components.
PongPanel(int startLevel, boolean _autoPilot, boolean embedded, Sound _sound, LevelLoader levelLoader, ImageLoader _imageLoader)
          Creates a custom Pong component.
 
Method Summary
 void brickDead(int x, int y)
          Called when a brick is zapped.
 void brickHit(int x, int y)
          Called when a brick is hit but not zapped.
 void changeLevel(int levelNo)
          Changes the current level to the given level number and resets game state.
static void criticalError(java.lang.String message)
          Displays an error dialog, then exits.
static void criticalErrorDialog(java.lang.String message)
          An error dialog for critical error messages.
static void errorDialog(java.lang.String title, java.lang.String message)
          Displays a modal error dialog.
 void flashBrick(int x, int y, long time)
          Flashes a brick for time milliseconds.
 void gameOver()
          Called when all balls have been lost.
 long gameOverFor()
          Returns the time (in milliseconds) since the game ended.
static void handleException(java.lang.String title, java.lang.String message, java.lang.Throwable e)
          Display information and stack trace for the given exception, then exits.
static void handleException(java.lang.String title, java.lang.String message, java.lang.Throwable e, boolean die)
          Display information and stack trace for the given exception.
 boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
          Obsolete (FileImageLoader takes care of this now).
protected  void init(int startLevel, boolean _autoPilot, boolean embedded, Sound _sound, LevelLoader levelLoader, ImageLoader _imageLoader)
          Initializes the game state.
protected  void initImages(ImageLoader _imageLoader)
           
protected  void initLevels(LevelLoader levelLoader)
           
protected  void initSounds(Sound _sound)
           
protected  void initThreads()
           
 boolean isGameOver()
          Returns true if the game has ended because all balls have been lost.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void levelComplete()
          Called when all bricks have been cleared.
 void lostBall()
          Called when the ball is lost.
static void modalDialog(int icon, java.lang.String title, java.lang.String message)
          Displays a modal dialog (JOptionPane) with the given attributes.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void moveBall(int x, int y)
          Moves the ball to the given coordinates.
static java.lang.String pad(int l, char padding, java.lang.String s)
          Returns a new String padded to the given length by inserting the necessary number of the specified character at the beginning.
 void paint(java.awt.Graphics g)
           
 void paintBonusBalls(java.awt.Graphics g)
          Paints the Bonus Balls (if any on screen).
 void paintBricks(java.awt.Graphics g)
          Paint the active bricks.
 void paintCredits(java.awt.Graphics g)
          Paints the credits stuff.
 void paintText(java.awt.Graphics g)
          Paints the status text.
 void repaintCredits(double x, boolean showCredits)
          Hint that the credits row needs refreshing.
 void repaintStatus()
          Hints that the status row needs refreshing.
 void resetGame()
          Resets the game state.
 void resetPaddle()
          Resets the paddle state.
 void setAutoPilot(boolean b)
          Enabled or disables the silly auto pilot.
protected  void setCursor(int type)
           
 void setupBricks(Level l)
          Sets up the GUI and state tables according the given Level.
static void showHelp()
          Displays the in-game help.
 void start()
          Starts the game.
protected  void toggleCursor()
           
 void update(java.awt.Graphics g)
           
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PongPanel

public PongPanel()
          throws java.io.IOException
Creates a Pong component using the default values and components.

PongPanel

public PongPanel(int startLevel,
                 boolean _autoPilot,
                 boolean embedded,
                 Sound _sound,
                 LevelLoader levelLoader,
                 ImageLoader _imageLoader)
          throws java.io.IOException
Creates a custom Pong component.
Method Detail

initLevels

protected void initLevels(LevelLoader levelLoader)

initImages

protected void initImages(ImageLoader _imageLoader)
                   throws java.io.IOException

initSounds

protected void initSounds(Sound _sound)
                   throws java.io.IOException

initThreads

protected void initThreads()

toggleCursor

protected void toggleCursor()

setCursor

protected void setCursor(int type)

init

protected void init(int startLevel,
                    boolean _autoPilot,
                    boolean embedded,
                    Sound _sound,
                    LevelLoader levelLoader,
                    ImageLoader _imageLoader)
             throws java.io.IOException
Initializes the game state.

start

public void start()
Starts the game.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

setAutoPilot

public void setAutoPilot(boolean b)
Enabled or disables the silly auto pilot.

setupBricks

public void setupBricks(Level l)
Sets up the GUI and state tables according the given Level.

pad

public static java.lang.String pad(int l,
                                   char padding,
                                   java.lang.String s)
Returns a new String padded to the given length by inserting the necessary number of the specified character at the beginning.

resetGame

public void resetGame()
Resets the game state.

resetPaddle

public void resetPaddle()
Resets the paddle state.

lostBall

public void lostBall()
Called when the ball is lost.

gameOver

public void gameOver()
Called when all balls have been lost.

isGameOver

public boolean isGameOver()
Returns true if the game has ended because all balls have been lost.

gameOverFor

public long gameOverFor()
Returns the time (in milliseconds) since the game ended.

brickDead

public void brickDead(int x,
                      int y)
Called when a brick is zapped.

brickHit

public void brickHit(int x,
                     int y)
Called when a brick is hit but not zapped.

changeLevel

public void changeLevel(int levelNo)
Changes the current level to the given level number and resets game state.

levelComplete

public void levelComplete()
Called when all bricks have been cleared.

moveBall

public void moveBall(int x,
                     int y)
Moves the ball to the given coordinates.

paintBricks

public void paintBricks(java.awt.Graphics g)
Paint the active bricks. There are still some checks for not-yet-loadeds although they are no longer needed.

flashBrick

public void flashBrick(int x,
                       int y,
                       long time)
Flashes a brick for time milliseconds.

paintCredits

public void paintCredits(java.awt.Graphics g)
Paints the credits stuff.

paintText

public void paintText(java.awt.Graphics g)
Paints the status text.

paintBonusBalls

public void paintBonusBalls(java.awt.Graphics g)
Paints the Bonus Balls (if any on screen).

update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Component

repaintStatus

public void repaintStatus()
Hints that the status row needs refreshing.

repaintCredits

public void repaintCredits(double x,
                           boolean showCredits)
Hint that the credits row needs refreshing.

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
Obsolete (FileImageLoader takes care of this now).
Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Overrides:
imageUpdate in class java.awt.Component

showHelp

public static void showHelp()
Displays the in-game help.

modalDialog

public static void modalDialog(int icon,
                               java.lang.String title,
                               java.lang.String message)
Displays a modal dialog (JOptionPane) with the given attributes.

errorDialog

public static void errorDialog(java.lang.String title,
                               java.lang.String message)
Displays a modal error dialog.

criticalErrorDialog

public static void criticalErrorDialog(java.lang.String message)
An error dialog for critical error messages.

criticalError

public static void criticalError(java.lang.String message)
Displays an error dialog, then exits.

handleException

public static void handleException(java.lang.String title,
                                   java.lang.String message,
                                   java.lang.Throwable e)
Display information and stack trace for the given exception, then exits.

handleException

public static void handleException(java.lang.String title,
                                   java.lang.String message,
                                   java.lang.Throwable e,
                                   boolean die)
Display information and stack trace for the given exception. If die is true, the application will exit when the user clicks 'OK'.