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.

1080 Multimedia: Images, Animation, Audio and Video Chapter 18<br />

19<br />

20 // <strong>Java</strong> extension packages<br />

21 import javax.swing.*;<br />

22<br />

23 public class LogoApplet extends JApplet {<br />

24<br />

25 // obtain parameters from HTML and cus<strong>to</strong>mize applet<br />

26 public void init()<br />

27 {<br />

28 String parameter;<br />

29<br />

30 // get animation delay from HTML document<br />

31 parameter = getParameter( "animationdelay" );<br />

32<br />

33 int animationDelay = ( parameter == null ?<br />

34 50 : Integer.parseInt( parameter ) );<br />

35<br />

36 // get base image name from HTML document<br />

37 String imageName = getParameter( "imagename" );<br />

38<br />

39 // get <strong>to</strong>tal number of images from HTML document<br />

40 parameter = getParameter( "<strong>to</strong>talimages" );<br />

41<br />

42 int <strong>to</strong>talImages = ( parameter == null ?<br />

43 0 : Integer.parseInt( parameter ) );<br />

44<br />

45 // create instance of LogoAnima<strong>to</strong>r<br />

46 LogoAnima<strong>to</strong>r2 anima<strong>to</strong>r;<br />

47<br />

48 if ( imageName == null || <strong>to</strong>talImages == 0 )<br />

49 anima<strong>to</strong>r = new LogoAnima<strong>to</strong>r2();<br />

50 else<br />

51 anima<strong>to</strong>r = new LogoAnima<strong>to</strong>r2( <strong>to</strong>talImages,<br />

52 animationDelay, imageName );<br />

53<br />

54 // attach anima<strong>to</strong>r <strong>to</strong> applet and start animation<br />

55 getContentPane().add( anima<strong>to</strong>r );<br />

56 anima<strong>to</strong>r.startAnimation();<br />

57<br />

58 } // end method init<br />

59<br />

60 } // end class LogoApplet<br />

Fig. Fig. 18.4 18.4 Cus<strong>to</strong>mizing an animation applet via the param HTML tag (part 2 of 2).

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

Saved successfully!

Ooh no, something went wrong!