Java Doc for MediaTracker.java in  » 6.0-JDK-Modules » j2me » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.awt 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.awt.MediaTracker

MediaTracker
public class MediaTracker implements java.io.Serializable(Code)
The MediaTracker class is a utility class to track the status of a number of media objects. Media objects could include audio clips as well as images, though currently only images are supported.

To use a media tracker, create an instance of MediaTracker and call its addImage method for each image to be tracked. In addition, each image can be assigned a unique identifier. This identifier controls the priority order in which the images are fetched. It can also be used to identify unique subsets of the images that can be waited on independently. Images with a lower ID are loaded in preference to those with a higher ID number.

Here is an example:


 import java.applet.Applet;
 import java.awt.Color;
 import java.awt.Image;
 import java.awt.Graphics;
 import java.awt.MediaTracker;
 public class ImageBlaster extends Applet implements Runnable {
 MediaTracker tracker;
 Image bg;
 Image anim[] = new Image[5];
 int index;
 Thread animator;
 // Get the images for the background (id == 0) 
 // and the animation frames (id == 1) 
 // and add them to the MediaTracker
 public void init() {
 tracker = new MediaTracker(this);
 bg = getImage(getDocumentBase(), 
 "images/background.gif");
 tracker.addImage(bg, 0);
 for (int i = 0; i < 5; i++) {
 anim[i] = getImage(getDocumentBase(), 
 "images/anim"+i+".gif");
 tracker.addImage(anim[i], 1);
 }
 }
 // Start the animation thread.
 public void start() {
 animator = new Thread(this);
 animator.start();
 }
 // Stop the animation thread.
 public void stop() {
 animator.stop();
 animator = null;
 }
 // Run the animation thread.
 // First wait for the background image to fully load 
 // and paint.  Then wait for all of the animation 
 // frames to finish loading. Finally, loop and 
 // increment the animation frame index.
 public void run() {
 try {
 tracker.waitForID(0);
 tracker.waitForID(1);
 } catch (InterruptedException e) {
 return;
 }
 Thread me = Thread.currentThread();
 while (animator == me) {
 try {
 Thread.sleep(100);
 } catch (InterruptedException e) {
 break;
 }
 synchronized (this) {
 index++;
 if (index >= anim.length) {
 index = 0;
 }
 }
 repaint();
 }
 }
 // The background image fills the frame so we 
 // don't need to clear the applet on repaints. 
 // Just call the paint method.
 public void update(Graphics g) {
 paint(g);
 }
 // Paint a large red rectangle if there are any errors 
 // loading the images.  Otherwise always paint the 
 // background so that it appears incrementally as it 
 // is loading.  Finally, only paint the current animation 
 // frame if all of the frames (id == 1) are done loading,
 // so that we don't get partial animations.
 public void paint(Graphics g) {
 if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) {
 g.setColor(Color.red);
 g.fillRect(0, 0, size().width, size().height);
 return;
 }
 g.drawImage(bg, 0, 0, this);
 if (tracker.statusID(1, false) == MediaTracker.COMPLETE) {
 g.drawImage(anim[index], 10, 10, this);
 }
 }
 }
 


version:
   1.32, 08/19/02
author:
   Jim Graham
since:
   JDK1.0



Field Summary
final public static  intABORTED
     Flag indicating that the downloading of some media was aborted.
final public static  intCOMPLETE
     Flag indicating that the downloading of media was completed successfully.
final static  intDONE
    
final public static  intERRORED
     Flag indicating that the downloading of some media encountered an error.
final public static  intLOADING
     Flag indicating some media is currently being loaded.
transient  MediaEntryhead
    
 Componenttarget
    

Constructor Summary
public  MediaTracker(Component comp)
     Creates a media tracker to track images for a given component.

Method Summary
public  voidaddImage(Image image, int id)
     Adds an image to the list of images being tracked by this media tracker.
public synchronized  voidaddImage(Image image, int id, int w, int h)
     Adds a scaled image to the list of images being tracked by this media tracker.
public  booleancheckAll()
     Checks to see if all images being tracked by this media tracker have finished loading.
public  booleancheckAll(boolean load)
     Checks to see if all images being tracked by this media tracker have finished loading.
public  booleancheckID(int id)
     Checks to see if all images tracked by this media tracker that are tagged with the specified identifier have finished loading.
public  booleancheckID(int id, boolean load)
     Checks to see if all images tracked by this media tracker that are tagged with the specified identifier have finished loading.
public synchronized  Object[]getErrorsAny()
     Returns a list of all media that have encountered an error.
public synchronized  Object[]getErrorsID(int id)
     Returns a list of media with the specified ID that have encountered an error.
Parameters:
  id - the identifier of the images to check.
public synchronized  booleanisErrorAny()
     Checks the error status of all of the images.
public synchronized  booleanisErrorID(int id)
     Checks the error status of all of the images tracked by this media tracker with the specified identifier.
public synchronized  voidremoveImage(Image image)
     Remove the specified image from this media tracker.
public synchronized  voidremoveImage(Image image, int id)
     Remove the specified image from the specified tracking ID of this media tracker.
public synchronized  voidremoveImage(Image image, int id, int width, int height)
     Remove the specified image with the specified width, height, and ID from this media tracker.
synchronized  voidsetDone()
    
public  intstatusAll(boolean load)
     Calculates and returns the bitwise inclusive OR of the status of all media that are tracked by this media tracker.
public  intstatusID(int id, boolean load)
     Calculates and returns the bitwise inclusive OR of the status of all media with the specified identifier that are tracked by this media tracker.
public  voidwaitForAll()
     Starts loading all images tracked by this media tracker.
public synchronized  booleanwaitForAll(long ms)
     Starts loading all images tracked by this media tracker.
public  voidwaitForID(int id)
     Starts loading all images tracked by this media tracker with the specified identifier.
public synchronized  booleanwaitForID(int id, long ms)
     Starts loading all images tracked by this media tracker with the specified identifier.

Field Detail
ABORTED
final public static int ABORTED(Code)
Flag indicating that the downloading of some media was aborted.
See Also:   java.awt.MediaTracker.statusAll
See Also:   java.awt.MediaTracker.statusID
since:
   JDK1.0



COMPLETE
final public static int COMPLETE(Code)
Flag indicating that the downloading of media was completed successfully.
See Also:   java.awt.MediaTracker.statusAll
See Also:   java.awt.MediaTracker.statusID
since:
   JDK1.0



DONE
final static int DONE(Code)



ERRORED
final public static int ERRORED(Code)
Flag indicating that the downloading of some media encountered an error.
See Also:   java.awt.MediaTracker.statusAll
See Also:   java.awt.MediaTracker.statusID
since:
   JDK1.0



LOADING
final public static int LOADING(Code)
Flag indicating some media is currently being loaded.
See Also:   java.awt.MediaTracker.statusAll
See Also:   java.awt.MediaTracker.statusID
since:
   JDK1.0



head
transient MediaEntry head(Code)



target
Component target(Code)




Constructor Detail
MediaTracker
public MediaTracker(Component comp)(Code)
Creates a media tracker to track images for a given component.
Parameters:
  comp - the component on which the images will eventually be drawn.
since:
   JDK1.0




Method Detail
addImage
public void addImage(Image image, int id)(Code)
Adds an image to the list of images being tracked by this media tracker. The image will eventually be rendered at its default (unscaled) size.
Parameters:
  image - the image to be tracked.
Parameters:
  id - an identifier used to track this image.
since:
   JDK1.0



addImage
public synchronized void addImage(Image image, int id, int w, int h)(Code)
Adds a scaled image to the list of images being tracked by this media tracker. The image will eventually be rendered at the indicated width and height.
Parameters:
  image - the image to be tracked.
Parameters:
  id - an identifier that can be used to track this image.
Parameters:
  w - the width at which the image is rendered.
Parameters:
  h - the height at which the image is rendered.
since:
   JDK1.0



checkAll
public boolean checkAll()(Code)
Checks to see if all images being tracked by this media tracker have finished loading.

This method does not start loading the images if they are not already loading.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny or isErrorID methods to check for errors. true if all images have finished loading, have been aborted, or have encountered an error; false otherwise.
See Also:   java.awt.MediaTracker.checkAll(boolean)
See Also:   java.awt.MediaTracker.checkID
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID
since:
   JDK1.0




checkAll
public boolean checkAll(boolean load)(Code)
Checks to see if all images being tracked by this media tracker have finished loading.

If the value of the load flag is true, then this method starts loading any images that are not yet being loaded.

If there is an error while loading or scaling an image, that image is considered to have finished loading. Use the isErrorAny and isErrorID methods to check for errors.
Parameters:
  load - if true, start loading any images that are not yet being loaded. true if all images have finished loading, have been aborted, or have encountered an error; false otherwise.
See Also:   java.awt.MediaTracker.checkID
See Also:   java.awt.MediaTracker.checkAll
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID(int)
since:
   JDK1.0




checkID
public boolean checkID(int id)(Code)
Checks to see if all images tracked by this media tracker that are tagged with the specified identifier have finished loading.

This method does not start loading the images if they are not already loading.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny or isErrorID methods to check for errors.
Parameters:
  id - the identifier of the images to check. true if all images have finished loading, have been aborted, or have encountered an error; false otherwise.
See Also:   java.awt.MediaTracker.checkID(intboolean)
See Also:   java.awt.MediaTracker.checkAll
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID(int)
since:
   JDK1.0




checkID
public boolean checkID(int id, boolean load)(Code)
Checks to see if all images tracked by this media tracker that are tagged with the specified identifier have finished loading.

If the value of the load flag is true, then this method starts loading any images that are not yet being loaded.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny or isErrorID methods to check for errors.
Parameters:
  id - the identifier of the images to check.
Parameters:
  load - if true, start loading any images that are not yet being loaded. true if all images have finished loading, have been aborted, or have encountered an error; false otherwise.
See Also:   java.awt.MediaTracker.checkID(intboolean)
See Also:   java.awt.MediaTracker.checkAll
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID(int)
since:
   JDK1.0




getErrorsAny
public synchronized Object[] getErrorsAny()(Code)
Returns a list of all media that have encountered an error. an array of media objects tracked by this media tracker that have encountered an error, or null if there are none with errors.
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.getErrorsID
since:
   JDK1.0



getErrorsID
public synchronized Object[] getErrorsID(int id)(Code)
Returns a list of media with the specified ID that have encountered an error.
Parameters:
  id - the identifier of the images to check. an array of media objects tracked by this media tracker with the specified identifier that have encountered an error, or null if there are none with errors.
See Also:   java.awt.MediaTracker.isErrorID
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.getErrorsAny
since:
   JDK1.0



isErrorAny
public synchronized boolean isErrorAny()(Code)
Checks the error status of all of the images. true if any of the images trackedby this media tracker had an error during loading; false otherwise.
See Also:   java.awt.MediaTracker.isErrorID
See Also:   java.awt.MediaTracker.getErrorsAny
since:
   JDK1.0



isErrorID
public synchronized boolean isErrorID(int id)(Code)
Checks the error status of all of the images tracked by this media tracker with the specified identifier.
Parameters:
  id - the identifier of the images to check. true if any of the images with the specified identifier had an error during loading; false otherwise.
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.getErrorsID
since:
   JDK1.0



removeImage
public synchronized void removeImage(Image image)(Code)
Remove the specified image from this media tracker. All instances of the specified image are removed, regardless of scale or ID.
Parameters:
  image - the image to be removed
See Also:   java.awt.MediaTracker.removeImage(java.awt.Imageint)
See Also:   java.awt.MediaTracker.removeImage(java.awt.Imageintintint)
since:
   JDK1.1



removeImage
public synchronized void removeImage(Image image, int id)(Code)
Remove the specified image from the specified tracking ID of this media tracker. All instances of Image being tracked under the specified ID are removed regardless of scale.
Parameters:
  image - the image to be removed.
Parameters:
  id - the tracking ID frrom which to remove the image.
See Also:   java.awt.MediaTracker.removeImage(java.awt.Image)
See Also:   java.awt.MediaTracker.removeImage(java.awt.Imageintintint)
since:
   JDK1.1



removeImage
public synchronized void removeImage(Image image, int id, int width, int height)(Code)
Remove the specified image with the specified width, height, and ID from this media tracker. Only the specified instance (with any duplicates) is removed.
Parameters:
  image - the image to be removed
Parameters:
  id - the tracking ID from which to remove the image.
Parameters:
  width - the width to remove (-1 for unscaled).
Parameters:
  height - the height to remove (-1 for unscaled).
See Also:   java.awt.MediaTracker.removeImage(java.awt.Image)
See Also:   java.awt.MediaTracker.removeImage(java.awt.Imageint)
since:
   JDK1.1



setDone
synchronized void setDone()(Code)



statusAll
public int statusAll(boolean load)(Code)
Calculates and returns the bitwise inclusive OR of the status of all media that are tracked by this media tracker.

Possible flags defined by the MediaTracker class are LOADING, ABORTED, ERRORED, and COMPLETE. An image that hasn't started loading has zero as its status.

If the value of load is true, then this method starts loading any images that are not yet being loaded.
Parameters:
  load - if true, start loading any images that are not yet being loaded. the bitwise inclusive OR of the status of all of the media being tracked.
See Also:   java.awt.MediaTracker.statusID(intboolean)
See Also:   java.awt.MediaTracker.LOADING
See Also:   java.awt.MediaTracker.ABORTED
See Also:   java.awt.MediaTracker.ERRORED
See Also:   java.awt.MediaTracker.COMPLETE
since:
   JDK1.0




statusID
public int statusID(int id, boolean load)(Code)
Calculates and returns the bitwise inclusive OR of the status of all media with the specified identifier that are tracked by this media tracker.

Possible flags defined by the MediaTracker class are LOADING, ABORTED, ERRORED, and COMPLETE. An image that hasn't started loading has zero as its status.

If the value of load is true, then this method starts loading any images that are not yet being loaded.
Parameters:
  id - the identifier of the images to check.
Parameters:
  load - if true, start loading any images that are not yet being loaded. the bitwise inclusive OR of the status of all of the media with the specifiedidentifier that are being tracked.
See Also:   java.awt.MediaTracker.statusAll(boolean)
See Also:   java.awt.MediaTracker.LOADING
See Also:   java.awt.MediaTracker.ABORTED
See Also:   java.awt.MediaTracker.ERRORED
See Also:   java.awt.MediaTracker.COMPLETE
since:
   JDK1.0




waitForAll
public void waitForAll() throws InterruptedException(Code)
Starts loading all images tracked by this media tracker. This method waits until all the images being tracked have finished loading.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny or isErrorID methods to check for errors.
See Also:   java.awt.MediaTracker.waitForID(int)
See Also:   java.awt.MediaTracker.waitForAll(long)
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID
exception:
  InterruptedException - if another thread has interrupted this thread.
since:
   JDK1.0




waitForAll
public synchronized boolean waitForAll(long ms) throws InterruptedException(Code)
Starts loading all images tracked by this media tracker. This method waits until all the images being tracked have finished loading, or until the length of time specified in milliseconds by the ms argument has passed.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny or isErrorID methods to check for errors.
Parameters:
  ms - the number of milliseconds to wait for the loading to complete. true if all images were successfully loaded; false otherwise.
See Also:   java.awt.MediaTracker.waitForID(int)
See Also:   java.awt.MediaTracker.waitForAll(long)
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID
exception:
  InterruptedException - if another thread has interrupted this thread.
since:
   JDK1.0




waitForID
public void waitForID(int id) throws InterruptedException(Code)
Starts loading all images tracked by this media tracker with the specified identifier. This method waits until all the images with the specified identifier have finished loading.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny and isErrorID methods to check for errors.
Parameters:
  id - the identifier of the images to check.
See Also:   java.awt.MediaTracker.waitForAll
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID(int)
exception:
  InterruptedException - if another thread has interrupted this thread.
since:
   JDK1.0




waitForID
public synchronized boolean waitForID(int id, long ms) throws InterruptedException(Code)
Starts loading all images tracked by this media tracker with the specified identifier. This method waits until all the images with the specified identifier have finished loading, or until the length of time specified in milliseconds by the ms argument has passed.

If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the statusID, isErrorID, and isErrorAny methods to check for errors.
Parameters:
  id - the identifier of the images to check.
Parameters:
  ms - the length of time, in milliseconds, to wait for the loading to complete.
See Also:   java.awt.MediaTracker.waitForAll
See Also:   java.awt.MediaTracker.waitForID(int)
See Also:   java.awt.MediaTracker.statusID
See Also:   java.awt.MediaTracker.isErrorAny
See Also:   java.awt.MediaTracker.isErrorID(int)
exception:
  InterruptedException - if another thread has interrupted this thread.
since:
   JDK1.0




Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.