26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1326 <strong>Java</strong> Media Framework and <strong>Java</strong> Sound (on CD) Chapter 22<br />

123 }<br />

124<br />

125 // set animation rate<br />

126 public void setAnimationRate( int rate )<br />

127 {<br />

128 animationRate = rate;<br />

129 }<br />

130<br />

131 // get animation rate<br />

132 public int getAnimationRate()<br />

133 {<br />

134 return animationRate;<br />

135 }<br />

136<br />

137 // set whether animation should loop<br />

138 public void setLoop( boolean loopAnimation )<br />

139 {<br />

140 loop = loopAnimation;<br />

141 }<br />

142<br />

143 // get whether animation should loop<br />

144 public boolean isLoop()<br />

145 {<br />

146 return loop;<br />

147 }<br />

148<br />

149 // get whether <strong>to</strong> display last frame at animation end<br />

150 private boolean isDisplayLastFrame()<br />

151 {<br />

152 return displayLastFrame;<br />

153 }<br />

154<br />

155 // set whether <strong>to</strong> display last frame at animation end<br />

156 public void setDisplayLastFrame( boolean displayFrame )<br />

157 {<br />

158 displayLastFrame = displayFrame;<br />

159 }<br />

160<br />

161 // start playing animation sequence of given index<br />

162 public void playAnimation( int frameSequence )<br />

163 {<br />

164 currentAnimation = frameSequence;<br />

165 currentFrameCounter = 0;<br />

166 setAnimating( true );<br />

167 }<br />

168 }<br />

Fig. Fig. Fig. 22.12 22.12 22.12 Class AnimatedPanel represents and displays an animated object from<br />

the model (part 4 of 4).<br />

Class AnimatedPanel chooses the ImageIcon object <strong>to</strong> be drawn on screen from<br />

among several ImageIcon objects s<strong>to</strong>red in array imageIcons (line 23). Class AnimatedPanel<br />

determines the ImageIcon object according <strong>to</strong> a series of frame sequence<br />

references, s<strong>to</strong>red in List frameSequences (line 26). A frame sequence is an array of

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!