DOC PREVIEW
LETU COSC 2103 - Chapter 19 – Multimedia: Images, Animation and Audio

This preview shows page 1-2-3-19-20-39-40-41 out of 41 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 19 – Multimedia: Images, Animation and Audio19.1 Introduction19.1 Introduction (cont.)19.2 Loading, Displaying and Scaling ImagesLoadImageAndScale.java Line 15 Line 16 Line 22 Line 25LoadImageAndScale.java Line 28 Program Output19.3 Animating a Series of ImagesLogoAnimator.java Line 23 Lines 26 and 28LogoAnimator.java Lines 36-45 Lines 48-51LogoAnimator.java Line 69LogoAnimator.java19.4 Image MapsImageMap.java Lines 18-30ImageMap.java Lines 32-45 Lines 63-76ImageMap.java Line 62ImageMap.java Program OutputSlide 1719.5 Loading and Playing Audio ClipsLoadAudioAndPlay.java Line 10LoadAudioAndPlay.java Lines 62-63LoadAudioAndPlay.java Lines 68-59LoadAudioAndPlay.java Line 77 Line 80 Line 8319.7 (Optional Case Study) Thinking About Objects: Animation and Sound in the View19.7 (Optional Case Study) Thinking About Objects: Animation and Sound in the View (cont.)ImagePanel.java Line 13 Line 16 Line 19 Line 25ImagePanel.java Lines 41-42ImagePanel.java Lines 54-60 Lines 63-67 Lines 70-74ImagePanel.java Lines 77-81ImagePanel.java Lines 103-118MovingPanel.java Line 13 Lines 20-21MovingPanel.java Lines 38-52MovingPanel.java Lines 68-84AnimatedPanel.java Line 12 Lines 19-20 Line 23 Lines 26-27AnimatedPanel.java Lines 44-49 Lines 56-70AnimatedPanel.java Lines 61-69 Lines 73-99 Lines 84-93AnimatedPanel.java Lines 88-91 Lines 96-97AnimatedPanel.javaAnimatedPanel.java Lines 162-16719.7 (Optional Case Study) Thinking About Objects: Animation and Sound in the View (Cont.)SoundEffects.java Line 8 Lines 19-20SoundEffects.java 2003 Prentice Hall, Inc. All rights reserved.Chapter 19 – Multimedia: Images, Animation and AudioOutline19.1 Introduction19.2 Loading, Displaying and Scaling Images19.3 Animating a Series of Images19.4 Image Maps 19.5 Loading and Playing Audio Clips 19.6 Internet and World Wide Web Resources 19.7 (Optional Case Study) Thinking About Objects: Animation and Sound in the View 2003 Prentice Hall, Inc. All rights reserved.19.1 Introduction•Multimedia–Use of sound, image, graphics and video–Makes applications “come alive” 2003 Prentice Hall, Inc. All rights reserved.19.1 Introduction (cont.)•This chapter focuses on–Image-manipulation basics–Creating smooth animations–Playing audio files (via AudioClip interface)–Creating image maps 2003 Prentice Hall, Inc. All rights reserved.19.2 Loading, Displaying and Scaling Images•Demonstrate some Java multimedia capabilities–java.awt.Image•abstract class (cannot be instantiated)•Can represent several image file formats–e.g., GIF, JPEG and PNG–javax.swing.ImageIcon•Concrete class 2003 Prentice Hall, Inc.All rights reserved.OutlineLoadImageAndScale.javaLine 15 Line 16Line 22Line 251 // Fig. 19.1: LoadImageAndScale.java2 // Load an image and display it in its original size and twice its 3 // original size. Load and display the same image as an ImageIcon.4 import java.applet.Applet;5 import java.awt.*;6 import javax.swing.*;7 8 public class LoadImageAndScale extends JApplet {9 private Image logo1; 10 private ImageIcon logo2;11 12 // load image when applet is loaded13 public void init()14 {15 logo1 = getImage( getDocumentBase(), "logo.gif" );16 logo2 = new ImageIcon( "logo.gif" ); 17 }18 19 // display image20 public void paint( Graphics g )21 { 22 g.drawImage( logo1, 0, 0, this ); // draw original image23 24 // draw image to fit the width and the height less 120 pixels25 g.drawImage( logo1, 0, 120, getWidth(), getHeight() - 120, this );Objects of class Image must be created via method getImageObjects of class ImageIcon may be created via ImageIcon constructorMethod drawImage displays Image object on screenOverloaded method drawImage displays scaled Image object on screen 2003 Prentice Hall, Inc.All rights reserved.OutlineLoadImageAndScale.java Line 28Program Output26 27 // draw icon using its paintIcon method28 logo2.paintIcon( this, g, 180, 0 );29 }30 31 } // end class LoadImageAndScaleMethod paintIcon displays ImageIcon object on screen 2003 Prentice Hall, Inc. All rights reserved.19.3 Animating a Series of Images•Demonstrate animating series of images–Images are stored in array 2003 Prentice Hall, Inc.All rights reserved.OutlineLogoAnimator.javaLine 23Lines 26 and 281 // Fig. 19.2: LogoAnimator.java2 // Animation of a series of images.3 import java.awt.*;4 import java.awt.event.*;5 import javax.swing.*;6 7 public class LogoAnimator extends JPanel implements ActionListener {8 9 private final static String IMAGE_NAME = "deitel"; // base image name10 protected ImageIcon images[]; // array of images11 12 private int totalImages = 30; // number of images13 private int currentImage = 0; // current image index14 private int animationDelay = 50; // millisecond delay15 private int width; // image width16 private int height; // image height17 18 private Timer animationTimer; // Timer drives animation19 20 // initialize LogoAnimator by loading images21 public LogoAnimator()22 {23 images = new ImageIcon[ totalImages ];24 25 // load images26 for ( int count = 0; count < images.length; ++count )27 images[ count ] = new ImageIcon( getClass().getResource(28 "images/" + IMAGE_NAME + count + ".gif" ) ); Create array that stores series of ImageIcon objectsLoad ImageIcon objects into array 2003 Prentice Hall, Inc.All rights reserved.OutlineLogoAnimator.java Lines 36-45Lines 48-5129 30 // this example assumes all images have the same width and height31 width = images[ 0 ].getIconWidth(); // get icon width32 height = images[ 0 ].getIconHeight(); // get icon height33 }34 35 // display current image 36 public void paintComponent( Graphics g )37 {38 super.paintComponent( g );39 40 images[ currentImage ].paintIcon( this, g, 0, 0 );41 42 // move to next image only if timer is running43 if ( animationTimer.isRunning() ) 44 currentImage = ( currentImage + 1 ) % totalImages;45 }46 47 // respond to Timer's event48 public void actionPerformed( ActionEvent actionEvent )49 {50 repaint(); // repaint animator51 }52 53


View Full Document

LETU COSC 2103 - Chapter 19 – Multimedia: Images, Animation and Audio

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Arrays

Arrays

11 pages

Load more
Download Chapter 19 – Multimedia: Images, Animation and Audio
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 19 – Multimedia: Images, Animation and Audio and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 19 – Multimedia: Images, Animation and Audio 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?