© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 30 -- Java Multimedia: Images, Animation, Audio.

Slides:



Advertisements
Similar presentations
 2004 Prentice Hall, Inc. All rights reserved. Chapter 28 – Multimedia: Audio, Video, Speech Synthesis and Recognition Outline 28.1 Introduction 28.2.
Advertisements

1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
1 L45 Multimedia: Applets and Applications. 2 OBJECTIVES  How to get and display images.  To create animations from sequences of images.  To create.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 14 Graphics.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
World Wide Web1 Applications World Wide Web. 2 Introduction What is hypertext model? Use of hypertext in World Wide Web (WWW) – HTML. WWW client-server.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
 2000 Prentice Hall, Inc. All rights reserved. Java Multimedia: Images, Animation, Audio and Video Outline 30.1 Introduction 30.2Loading, Displaying and.
 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Graphics and Multimedia In visual Studio. Net (C#)
 2000 Prentice Hall, Inc. All rights reserved. Chapter 16 - Multimedia: Images, Animation, Audio and Video Outline 16.1 Introduction 16.2Downloading the.
Computer Science [3] Java Programming II - Laboratory Course Lab 7: Multimedia: Applets and Applications Faculty of Engineering & IT Software Engineering.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Threads and Multimedia Animation, Images, Sound. Animation nAnimation, displaying a sequence of frames to create the illusion of motion, is a typical.
 2005 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 18 – Multimedia: Images, Animation, Audio and Video Outline 18.1 Introduction 18.2 Loading, Displaying.
(c) 2008 E.S.Boese All Rights Reserved. Threads and Media Chapter 8 - Lecture Slides 1.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 20 – Dynamic HTML: Path, Sequencer and Sprite ActiveX Controls Outline 20.1Introduction 20.2DirectAnimation.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Java Programming, Second Edition Chapter Seventeen Multithreading and Animation.
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
JavaScript, Fourth Edition
Timer Objects  regularly generates action events at programmer-specified time intervals  Timer class is in javax.swing package  Timer (int delay, ActionListener.
 2000 Prentice Hall, Inc. All rights reserved. Java Multimedia: Images, Animation, Audio and Video Outline 30.1 Introduction 30.2Loading, Displaying and.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 16 Applets and Multimedia.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Review of Graphics in Java,
High Performance Java Swing Animation David Wallace Croft Presented to the Plano Java Users Group Plano, TX Copyright 2004 David Wallace Croft.
Java Direct Manipulation Chris North cs3724: HCI.
Java Programming Working with Sound and Images. Topics Learn about the paint() and repaint() methods Learn about paintComponent() method Use the drawString()
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
Chapter 16 Multimedia F Audio Files F Playing Audio F Running Audio on a Separate Thread F Displaying Images F Displaying a Sequence of Images  Using.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Creating a Java Application and Applet
1 Applets. 2 What is an applet? Applet: a Java program that can be inserted into a web page and run by loading that page in a browser brings web pages.
Introduction to Applets Chapter 21. Applets An applet is a Java application that is intended to be invoked and executed through a Web browser. Click Here.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
Chapter 14: Multimedia Audio Files Audio Files Playing Audio Playing Audio Running Audio on a Separate Thread Running Audio on a Separate Thread Displaying.
Mouse, Keyboard, Sounds, and Images JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Chapter 14 Applets and More. 2 Contents I. Introduction to Applets II. A Brief Introduction to HTML III. Creating Applets with Swing IV. Using AWT for.
Distributed Computing, M. L. Liu
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
Presentation transcript:

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter Java Multimedia: Images, Animation, Audio and Video Outline 30.1 Introduction 30.2Loading, Displaying and Scaling Images 30.3Loading and Playing Audio Clips 30.4Animating a Series of Images 30.5Animation Issues 30.6Customizing Applets via the HTML param Tag 30.7Image Maps 30.8Internet and World Wide Web Resources

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Objectives In this chapter, you will learn: –To understand how to get and display images. –To be able to create animations from sequences of images; to control animation speed and flicker. –To be able to get, play, loop and stop sounds. –To be able to monitor the loading of images with class MediaTracker ; to create image maps. –To customize applets with the param tag.

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Revolution in computer industry –Before, computers used for high-speed calculations –Now, data manipulation important Multimedia –"sizzle" of Java - images, sound, video –CDs, DVDs, video cards –Demands extraordinary computing power Fast processors making multimedia possible Java –Has built-in multimedia capabilities Most programming languages do not –Develop powerful multimedia applications

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.2Loading, Displaying and Scaling Images Java Multimedia –Graphics, images, animations, sounds, and video Begin with images Class Image ( java.awt ) –Abstract class, cannot create an object directly Must request that an Image be loaded and returned to you –Class Applet (superclass of JApplet ) has this method getImage( imageLocation, filename ); imageLocation - getDocumentBase() - URL (address) of HTML file filename - Java supports.gif and.jpg (.jpeg )

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.2Loading, Displaying and Scaling Images (II) Displaying Images with drawImage –Many overloaded versions g.drawImage( myImage, x, y, ImageObserver ); myImage - Image object x,y - coordinates to display image ImageObserver - object on which image is displayed –Use " this " to indicate the applet –Can be any object that implements ImageObserver interface –g.drawImage( myImage, x, y, width, height, ImageObserver ); width and height - dimensions of image (automatically scaled) –getWidth(), getHeight() - return dimensions of applet

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.2Loading, Displaying and Scaling Images (III) Class ImageIcon –Not an abstract class (can create objects) –Example constructor private ImageIcon myIcon; myIcon = new ImageIcon( "myIcon.gif" ); Displaying Icons with method paintIcon myIcon.paintIcon( Component, Graphics, x, y ) –Component - Component object on which to display image ( this ) –Graphics - Graphics object used to render image ( g ) –x, y - coordinates of Icon

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.2Loading, Displaying and Scaling Images (IV) Usage –ImageIcons are simpler than Images Create objects directly No need for ImageObserver reference –However, cannot scale ImageIcons Scaling –Use ImageIcon method getImage Returns Image reference This can be used with drawImage and be scaled

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoadImage- AndScale.java (Part 1 of 2)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoadImage- AndScale.java (Part 2 of 2) Program Output

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.3Loading and Playing Audio Clips Audio clips –Require speakers and a sound board –Sound engine - plays audio clips Supports.au,.wav,.aif,.mid Java Media Framework supports additional formats Playing audio clips –play method in Applet –Plays clip once, marked for garbage collection when finished play( location, soundFileName ); location - getDocumentBase (URL of HTML file) play( soundURL ); soundURL - URL that contains location and filename of clip

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.3Loading and Playing Audio Clips (II) Playing audio clips –Method play from AudioClip interface –More flexible than Applet method play Audio stored in program, can be reused –getAudioClip Returns reference to an AudioClip Same format as Applet method play –getAudioClip( location, filename ) –getAudioClip( soundURL ) –Once AudioClip loaded, use methods play - plays audio once loop - continuous loops audio in background stop - terminates clip that is currently playing

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoadAudioAndPlay. java (Part 1 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoadAudioAndPlay. java (Part 2 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoadAudioAndPlay. java (Part 3 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Program Output

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.4Animating a Series of Images Following example –Use a series of images stored in an array –Use same techniques to load and display ImageIcons Class Timer –Generates ActionEvents at a fixed interval in milliseconds Timer ( animationDelay, ActionListener ); ActionListener - ActionListener that will respond to ActionEvents –Methods start stop restart isRunning

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.4Animating a Series of Images (II) Method repaint –Calls update, which calls paintComponent Subclasses of JComponent should draw in method paintComponent Call superclass's paintComponent to make sure Swing components displayed properly View area –Width and height specify entire window, not client area –Dimension objects Contain width and height values myDimObject = new Dimension( 100, 200 ); myDimObject.width

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.4Animating a Series of Images (III) getImageLoadStatus –ImageIcon method Determines if image is completely loaded into memory Only complete images should be displayed (smooth animation) –If loaded, returns MediaTracker.COMPLETE –MediaTracker Can determine when images are loaded, or force program to wait if not ImageIcon creates our MediaTracker for us

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoopAnimator.java (Part 1 of 4)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoopAnimator.java (Part 2 of 4)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoopAnimator.java (Part 3 of 4)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LoopAnimator.java (Part 4 of 4)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Program Output

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.5Animation Issues Storing images –Interlaced/non-interlaced formats Specifies order in which pixels are stored Non-interlaced - pixels stored in order they appear on screen –Image appears in chunks from top to bottom as it is loaded Interlaced - pixels stored in rows, but out of order –Image appears to fade in and become more clear Animation flickers –Due to update being called in response to repaint –In AWT GUI components Draws filled rectangle in background color where image was Draw image, sleep, clear background (flicker), draw next image... –Swing's JPanel overrides update to avoid this

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.5Animation Issues (II) Double buffering –Used to smooth animations –Program renders one image on screen Builds next image in off-screen buffer –When time to display next image, done smoothly Partial images user would have seen (while image loads) are hidden All pixels for next image displayed at once –Space/Time tradeoff Reduces flicker, but can slow animation speed and uses more memory –Used by Swing GUI components by default

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.6Customizing Applets via the HTML param Tag Applets –Customize through parameters in HTML file that invokes it –Invokes applet LogoApplet –param tags Each has a name and a value Use Applet method getParameter (returns a String ) parameter = getParameter( "animationdelay" );

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.6Customizing Applets via the HTML param Tag (II) Following example –Use the LogoAnimator class as before, but modified slightly –Create Applet LogoApplet Takes parameters Creates LogoAnimator object using the parameters Plays animation

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoAnimator.java (Part 1 of 5)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoAnimator.java (Part 2 of 5)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoAnimator.java (Part 3 of 5)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoAnimator.java (Part 4 of 5)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoAnimator.java (Part 5 of 5) LogoApplet.java (Part 1 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoApplet.java (Part 2 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. LogoApplet.java (Part 3 of 3) Program Output

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.7Image Maps Image map –Image that has hot areas User can click to accomplish a task –Bubble help When mouse over particular point in screen, small message displayed in status bar In the following example –Load several images –Use event handler mouseMoved to find x-coordinate –Based on the x-coordinate, display a message

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. ImageMap.java (Part 1 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. ImageMap.java (Part 2 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. ImageMap.java (Part 3 of 3)

Outline © Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Program Output

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30.8Internet and World Wide Web Resources Internet and web resources for multimedia related sites. The NASA multimedia gallery The Sunsite Japan Multimedia Collection The Australian National Botanic Gardens Web site provides links to sounds of many animals.