Results 1 to 6 of 6

Thread: What is the use of MediaTracker class?

  1. #1
    Join Date
    Jan 2010
    Posts
    76

    What is the use of MediaTracker class?

    Hello friends,

    I am new to the java programming concept. I want to be aware about the MediaTracker class of java programming language. I don't have any idea about constructors and methods of MediaTracker class. I wonder if you let me know about the MediaTracker class. If possible then also provide suitable example for the same java class. I will really appreciate your help.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is the use of MediaTracker class?

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: What is the use of MediaTracker class?

    Example of MediaTracker class:
    Code:
    import java.awt.MediaTracker;
    import java.net.MalformedURLException;
    import javax.swing.JPanel;
    
    public class MTMainClass extends JPanel
     {
    
      public void load() throws MalformedURLException
     {
        URL url1 = new URL("image address");
        Image im1 = Toolkit.getDefaultToolkit().getImage(url1);
    
        MediaTracker mt1 = new MediaTracker(this);
        mt1.addImage(im1, 0);
        try {
          mt1.waitForID(0);
        } catch (InterruptedException e) 
    {
          System.err.println("Unexpected interrupt in waitForID!");
          return;
        }
        if (mt1.isErrorID(0))
     {
          System.err.println("Couldn't load image file " + url);
          return;
        }
      }
    
      public static void main(String[] arlgs) {
      }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: What is the use of MediaTracker class?

    To use features of MediaTracker class, you need to be aware about following it's methods:
    1. waitForID(int id, long msd)
    2. waitForAll(long msd)
    3. statusID(int id, boolean bln)
    4. removeImage(Image img, int id)
    5. checkAll(boolean bln)

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What is the use of MediaTracker class?

    Following java example will show you how to use addImage() method of MediaTracker class:
    Code:
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.net.URL;
    
    public class MediaTrackerDemo extends JPanel {
    
      public void load() throws MalformedURLException {
        URL ul01 = new URL("image address");
        Image imF = Toolkit.getDefaultToolkit().getImage(ul01);
    
        MediaTracker mtF = new MediaTracker(this);
        mt.addImage(imF, 0);
        try {
          mtF.waitForID(0);
        } catch (InterruptedException e) {
          System.err.println("Unexpected interrupt in waitForID!");
          return;
        }
        if (mtF.isErrorID(0)) {
          System.err.println("Couldn't load image file " + ul01);
          return;
        }
      }
      public static void main(String[] avrgs) {
    // create oblect here
    
      }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: What is the use of MediaTracker class?

    The use of MediaTracker class is for tracking of media objects status. This java class is hired from package known as 'java.lang.Object'. This class implements all the Serializable classes. There is only single constructor is available for MediaTracker class i.e MediaTracker(). You just need to pass the value of component as a input parameter for this constructors. You can use four fields with this class.

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. What is the difference between Local class and global class in C++?
    By Dëfrim in forum Software Development
    Replies: 4
    Last Post: 03-01-2011, 10:44 PM
  3. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,012,443.77493 seconds with 16 queries