sprite.spritesound
Class SoundSprite

java.lang.Object
  extended by sprite.Sprite
      extended by sprite.spritesound.SoundSprite
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.sound.sampled.LineListener

public class SoundSprite
extends Sprite
implements java.io.Serializable, javax.sound.sampled.LineListener

Created on November 20, 2006, 5:14 PM Creates a sound sprite which can load and play sound files.
To preserve the line of inheritance, updateSprite may also be used to play the sound file.
Based on ClipInfo.java from "Killer Game Programming in Java."

Version:
t.6
Author:
Eric Angeli
See Also:
Serialized Form

Field Summary
 
Fields inherited from class sprite.Sprite
active, visible
 
Constructor Summary
SoundSprite()
          Creates a new instance of SoundSprite
 
Method Summary
 void close()
          Closes the sound clip.
 javax.sound.sampled.Clip getClip()
          Gets the clip.
 java.text.DecimalFormat getDf()
          Gets the demical format of the clip.
 java.lang.String getFileName()
          Gets the file name.
 boolean isIsLooping()
          The looping state.
 boolean isIsPlaying()
          The current play state of the sound clip.
 void loadClip()
          Loads the sound clip from the specified fileName.
 void paintSprite(java.awt.Graphics2D g)
          Paints the sprite.
Sound sprite has an empty paintSprite method since there is nothing to paint.
 void pause()
          Pause the sound slip.
 void play()
          plays the sound clip.
 void resume()
          Resumes the sound clip.
 void setClip(javax.sound.sampled.Clip clip)
          Sets the clip.
 void setDf(java.text.DecimalFormat df)
          Sets the decimal format.
 void setFileName(java.lang.String fileName)
          Sets the file name.
 void setIsLooping(boolean isLooping)
          Sets the loop state.
 void setIsPlaying(boolean isPlaying)
          Set the current playing state.
 void stop()
          stops the sound clip.
 void update(javax.sound.sampled.LineEvent le)
          Handles the update for the line event.
 void updateSprite(java.awt.Component c)
          Updates the sprite.
In the case of soundSprite, this plays the sound.
 
Methods inherited from class sprite.Sprite
addPropertyChangeListener, getPropertySupport, isActive, isVisible, removePropertyChangeListener, restore, setActive, setVisible, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoundSprite

public SoundSprite()
Creates a new instance of SoundSprite

Method Detail

updateSprite

public void updateSprite(java.awt.Component c)
Updates the sprite.
In the case of soundSprite, this plays the sound.

Specified by:
updateSprite in class Sprite
Parameters:
c - The component that contains this sprite.

paintSprite

public void paintSprite(java.awt.Graphics2D g)
Paints the sprite.
Sound sprite has an empty paintSprite method since there is nothing to paint.

Specified by:
paintSprite in class Sprite
Parameters:
g - the graphics used for painting.

getFileName

public java.lang.String getFileName()
Gets the file name.

Returns:
The path and filename.

setFileName

public void setFileName(java.lang.String fileName)
Sets the file name.
The file name also must include the path.

Parameters:
fileName - The new file name.

getClip

public javax.sound.sampled.Clip getClip()
Gets the clip.

Returns:
The clip that has been loaded.

setClip

public void setClip(javax.sound.sampled.Clip clip)
Sets the clip.

Parameters:
clip - The new sound clip.

isIsLooping

public boolean isIsLooping()
The looping state.
Whether or not the sound clip is played on a loop.

Returns:
True if looping otherwise false.

setIsLooping

public void setIsLooping(boolean isLooping)
Sets the loop state.

Parameters:
isLooping - The new loop state.

getDf

public java.text.DecimalFormat getDf()
Gets the demical format of the clip.

Returns:
The decimal format.

setDf

public void setDf(java.text.DecimalFormat df)
Sets the decimal format.

Parameters:
df - The new decimal format.

loadClip

public void loadClip()
Loads the sound clip from the specified fileName.


update

public void update(javax.sound.sampled.LineEvent le)
Handles the update for the line event.

Specified by:
update in interface javax.sound.sampled.LineListener
Parameters:
le - The line event that triggered the update.

close

public void close()
Closes the sound clip.


play

public void play()
plays the sound clip.


stop

public void stop()
stops the sound clip.


pause

public void pause()
Pause the sound slip.


resume

public void resume()
Resumes the sound clip.


isIsPlaying

public boolean isIsPlaying()
The current play state of the sound clip.

Returns:
True if currently playing, false if not.

setIsPlaying

public void setIsPlaying(boolean isPlaying)
Set the current playing state.

Parameters:
isPlaying - The new playing state of the sound. True if playing, false if not.