MediaTracker


The html file should have the applet tag for the class file

a1.html

<applet code="zzz" width=350 height=250></applet>


The import statements for the all programs will be

import java.applet.*;
import java.awt.*;
import java.awt.image.*;

zzz.java
public class zzz extends Applet
{       Image b;
        public void init()
        {       b=getImage(getDocumentBase(), "borderex1.gif");
        }
        public void paint(Graphics g)
        {       g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet
{       MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(), "borderex1.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e)
                {       return;
                }
        }
        public void paint(Graphics g)
        {       g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet implements Runnable
{       Thread a;
        MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(), "borderex1.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e) {return;}
                a=new Thread(this);
                a.start();
        }
        public void run()
        {       while (true)
                {       try Thread.sleep(100);
                        catch (InterruptedException e)
                        {       break;
                        }
                        repaint();
                }
        }
        public void paint(Graphics g)
        {       g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet implements Runnable
{       Thread a;
        MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(), "borderex1.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e) {return;}
                a=new Thread(this);
                a.start();
        }
        public void run()
        {       while (true)
                {       try Thread.sleep(100);
                        catch (InterruptedException e)
                        {       break;
                        }
                        repaint();
                }
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet
{       MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(), "borderex1.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e)
                {       return;
                }
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       if ((t.statusID(0,false) & MediaTracker.COMPLETE) != 0) 
                        g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet
{       MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(),"borderex1.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e)
                {       return;
                }
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       if ((t.statusID(1,true) & MediaTracker.COMPLETE) != 0) 
                        g.drawImage(b, 0, 0, this);
                else
                        showStatus("Status is false");
        }
}
zzz.java
public class zzz extends Applet
{       Image b;
        public void init()
        {       b=getImage(getDocumentBase(), "borderex0.gif");
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       showStatus("hi");
                g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet
{       MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(),"borderex0.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e)
                {       return;
                }
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       if ((t.statusID(0,true) & MediaTracker.COMPLETE) != 0) 
                        g.drawImage(b, 0, 0, this);
                else
                        showStatus("Status is false");
        }
}
zzz.java
public class zzz extends Applet
{       MediaTracker t;
        Image b;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(), "borderex0.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e)
                {       return;
                }
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       if (MediaTracker.ERRORED == 4)
                        showStatus("error");
                if ((t.statusID(0,true) & MediaTracker.COMPLETE) != 0)
                        g.drawImage(b, 0, 0, this);
        }
}
zzz.java
public class zzz extends Applet
{       MediaTracker t;
        Image b,b1;
        ImageProducer p;
        public void init()
        {       t=new MediaTracker(this);
                b=getImage(getDocumentBase(), "borderex0.gif");
                t.addImage(b,0);
                try t.waitForID(0);
                catch (InterruptedException e)
                {       return;
                }
        }
        public void update(Graphics g)
        {       paint(g);
        }
        public void paint(Graphics g)
        {       if ( t.isErrorAny() )
                        showStatus("is error any");
                if ((t.statusID(0,true) & MediaTracker.COMPLETE) != 0)
                        g.drawImage(b, 0, 0, this);
        }
}

Your comments , feedback , suggestions are most welcome. Let us know what you think .

A part of the whole in the nextchapter.

Back to the Java Page


Vijay Mukhi's Computer Institute
B-13, Everest Building, Tardeo, Bombay 400 034, India.
http://www.neca.com/~vmis
e-mail : vmukhi@giasbm01.vsnl.net.in
1