Källkoden för /anders.enges/java/blaster2.asp
<!--#include file="../inc/navstuff.asp" -->
<H4>Förbättrad variant</H4>
<p>Det är inte så intelligent att "hårdkoda" bildernas namn och antal i programmet.
Det skulle vara mycket bättre att
kunna ange bildernas namn när programmet körs.
Nedan kommer en variant på ImageBlaster klassen som kan
få angivet vilka bilder som skall användas.</p>
<h4>Skapa en ny klass:</h4>
<p>När du har ImageBlaster.java öppen i editorn så väljer du File, Save As, och ger den namnet
<b>ImageBlaster2.java</b>. Den borde dyka upp i samma projekt som den tidigare filen.</p>
<p>Modifiera även Page1.htm filen. Du kan gärna sätta till en applet till på samma sida. Koden
för att få in ImageBlaster2 finns nedan. </p>
<h4>Page1.htm</h4>
<pre>
<applet
     code=ImageBlaster<b>2</b>.class
     name=ImageBlaster<b>2</b>
     width=200
     height=100>
     <b><param name="imagecount" value="5">
     <param name="basename" value="images/anim">
     <param name="filetype" value="jpg">
     <param name="background" value="images/background.gif">
     <param name="delay" value="1000"></b>
</applet>
</pre>
<h4>ImageBlaster2.java</h4>
<PRE>
<FONT COLOR="#0000FF">import</FONT> java.applet.Applet<FONT COLOR="#800000">;</FONT>
<FONT COLOR="#0000FF">import</FONT> java.awt.<FONT COLOR="#800000">*</FONT><FONT COLOR="#800000">;</FONT>

<FONT COLOR="#008000">//--------------------------------------------------------------</FONT>
<FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">class</FONT> ImageBlaster<b>2</b> <FONT COLOR="#0000FF">extends</FONT> Applet
     <FONT COLOR="#0000FF">implements</FONT> Runnable <FONT COLOR="#008000">// för att få ett flertrådigt program</FONT>

<FONT COLOR="#800000">{</FONT>
     <b><FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
     <FONT COLOR="#008000">// ett antal variabler</FONT>
     <FONT COLOR="#008000">// för enkelhetens skull ger vi dem samma startvärden som i </FONT>
     <FONT COLOR="#008000">// i föregåennde ImageBlaster</FONT>
     String basename <FONT COLOR="#800000">=</FONT> <FONT COLOR="#FF0000">"images/anim"</FONT><FONT COLOR="#800000">;</FONT>
     String filetype <FONT COLOR="#800000">=</FONT> <FONT COLOR="#FF0000">"jpg"</FONT><FONT COLOR="#800000">;</FONT>
     String background <FONT COLOR="#800000">=</FONT> <FONT COLOR="#FF0000">"images/background.gif"</FONT><FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#0000FF">int</FONT> delay <FONT COLOR="#800000">=</FONT> <FONT COLOR="#800080">1000</FONT><FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#0000FF">int</FONT> imagecount <FONT COLOR="#800000">=</FONT> <FONT COLOR="#800080">5</FONT><FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#008000">// ----------------------------------------------------------</FONT></b>
    
     <FONT COLOR="#008000">// MediaTrackern kan hålla reda på om alla bilder är laddade </FONT>
     MediaTracker tracker<FONT COLOR="#800000">;</FONT>
    
     <FONT COLOR="#008000">// bakgrundsbilden</FONT>
     Image bg<FONT COLOR="#800000">;</FONT>
    
     <b><FONT COLOR="#008000">// en array med (för tillfället ) okänt antal Images</FONT>
     <FONT COLOR="#008000">// OBS! Ändrad.</FONT>
     <FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
     Image anim<FONT COLOR="#800000">[</FONT><FONT COLOR="#800000">]</FONT> <FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#008000">// ----------------------------------------------------------</FONT></b>
    
     <FONT COLOR="#008000">// nuvarande bild</FONT>
     <FONT COLOR="#0000FF">int</FONT> index<FONT COLOR="#800000">;</FONT>
    
     <FONT COLOR="#008000">// en separat tråd</FONT>
     Thread animator<FONT COLOR="#800000">;</FONT>
    
     <FONT COLOR="#008000">// hämta bilden för bakgrunden (id = 0)</FONT>
     <FONT COLOR="#008000">// och de fem bilderna som skall animeras (id == 1) </FONT>
     <FONT COLOR="#008000">// och lägg in dem i MediaTrackern så att vi vet </FONT>
     <FONT COLOR="#008000">// när de är laddade</FONT>
     <FONT COLOR="#008000">// init är fortfarande startpunkten för Appletten</FONT>
     <FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">void</FONT> init<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>
     <FONT COLOR="#800000">{</FONT>
         <FONT COLOR="#008000">// skapa en MediaTracker som skall meddela oss </FONT>
         <FONT COLOR="#008000">// när bilderna är laddade</FONT>
         tracker <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">new</FONT> MediaTracker<FONT COLOR="#800000">(</FONT><FONT COLOR="#0000FF">this</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>

         <b><FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
         String param<FONT COLOR="#800000">;</FONT> <FONT COLOR="#008000">// en sträng att läsa in parametrar i </FONT>
         <FONT COLOR="#008000">// kolla om det fanns en rad med </FONT>
         <FONT COLOR="#008000">// <param name="basename" value="... i applet taggen</FONT>
         param <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">this</FONT>.getParameter<FONT COLOR="#800000">(</FONT><FONT COLOR="#FF0000">"basename"</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#008000">// om det fanns så sätter vi det värdet in i variabeln basename</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT> param.length<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">></FONT> <FONT COLOR="#800080">0</FONT> <FONT COLOR="#800000">)</FONT>
             basename <FONT COLOR="#800000">=</FONT> param<FONT COLOR="#800000">;</FONT>

         <FONT COLOR="#008000">// sedan kollar vi på motsvarande sätt de övriga parametrarna</FONT>
         param <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">this</FONT>.getParameter<FONT COLOR="#800000">(</FONT><FONT COLOR="#FF0000">"filetype"</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT> param.length<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">></FONT> <FONT COLOR="#800080">0</FONT> <FONT COLOR="#800000">)</FONT>
             filetype <FONT COLOR="#800000">=</FONT> param<FONT COLOR="#800000">;</FONT>
        
         param <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">this</FONT>.getParameter<FONT COLOR="#800000">(</FONT><FONT COLOR="#FF0000">"background"</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT> param.length<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">></FONT> <FONT COLOR="#800080">0</FONT> <FONT COLOR="#800000">)</FONT>
             background <FONT COLOR="#800000">=</FONT> param<FONT COLOR="#800000">;</FONT>
        
         param <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">this</FONT>.getParameter<FONT COLOR="#800000">(</FONT><FONT COLOR="#FF0000">"imagecount"</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT> param.length<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">></FONT> <FONT COLOR="#800080">0</FONT> <FONT COLOR="#800000">)</FONT>
             imagecount <FONT COLOR="#800000">=</FONT> Integer.parseInt<FONT COLOR="#800000">(</FONT>param<FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT> <FONT COLOR="#008000">// siffra</FONT>
        
         param <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">this</FONT>.getParameter<FONT COLOR="#800000">(</FONT><FONT COLOR="#FF0000">"delay"</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT> param.length<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">></FONT> <FONT COLOR="#800080">0</FONT> <FONT COLOR="#800000">)</FONT>
             delay <FONT COLOR="#800000">=</FONT> Integer.parseInt<FONT COLOR="#800000">(</FONT>param<FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT> <FONT COLOR="#008000">// siffra </FONT>
        
         <FONT COLOR="#008000">// nu vet vi hur många bilder vi skall ha</FONT>
         anim <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">new</FONT> Image<FONT COLOR="#800000">[</FONT>imagecount<FONT COLOR="#800000">]</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#008000">// ----------------------------------------------------------</FONT></b>
        
         <FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
         <FONT COLOR="#008000">// delvis ändrad</FONT>
         <FONT COLOR="#008000">// dels använder vi background variabeln</FONT>
         <FONT COLOR="#008000">// dels så har jag satt dit en kompletterande kod som gör att bilden</FONT>
         <FONT COLOR="#008000">// alltid fyller ut hela appleten - oavsett dess storlek</FONT>
         bg <FONT COLOR="#800000">=</FONT> getImage<FONT COLOR="#800000">(</FONT> getDocumentBase<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">,</FONT>
                 <b>background</b> <FONT COLOR="#800000">)</FONT><b>.getScaledInstance<FONT COLOR="#800000">(</FONT>
                                   <FONT COLOR="#0000FF">this</FONT>.getSize<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>.width<FONT COLOR="#800000">,</FONT>
                                   <FONT COLOR="#0000FF">this</FONT>.getSize<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>.height<FONT COLOR="#800000">,</FONT>
                                   Image.SCALE_SMOOTH <FONT COLOR="#800000">)</FONT><FONT COLOR="#800000"></b>;</FONT>
         <FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
         <FONT COLOR="#008000">// eftersom bilden inte laddas ommeddelbart så</FONT>
         <FONT COLOR="#008000">// säger vi åt vår MediaTracker att den skall meddela oss </FONT>
         <FONT COLOR="#008000">// när den finns tillgänglig</FONT>
         tracker.addImage<FONT COLOR="#800000">(</FONT> bg<FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">0</FONT> <FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
        
         <FONT COLOR="#008000">// hämta resten av bilderna som antas finnas i en images katalog</FONT>
         <b><FONT COLOR="#008000">// ----------------------------------------------------------</FONT></b>
         <FONT COLOR="#008000">// observera att 5:an är ändrad till imagecount i loopen</FONT>
         <FONT COLOR="#0000FF">for</FONT> <FONT COLOR="#800000">(</FONT> <FONT COLOR="#0000FF">int</FONT> i <FONT COLOR="#800000">=</FONT> <FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">;</FONT> i <FONT COLOR="#800000"><</FONT> <b>imagecount</b><FONT COLOR="#800000">;</FONT> i<FONT COLOR="#800000">+</FONT><FONT COLOR="#800000">+</FONT> <FONT COLOR="#800000">)</FONT>
         <b><FONT COLOR="#008000">// ----------------------------------------------------------</FONT></b>
         <FONT COLOR="#800000">{</FONT>
             <FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
             <FONT COLOR="#008000">// delvis ändrad</FONT>
             <FONT COLOR="#008000">// dels använder vi basename och filetype variablerna</FONT>
             <FONT COLOR="#008000">// dels så har jag satt dit en kompletterande kod som gör att </FONT>
             <FONT COLOR="#008000">// bilderna alltid fyller ut nästan hela appleten - oavsett </FONT>
             <FONT COLOR="#008000">// dess storlek</FONT>
             anim<FONT COLOR="#800000">[</FONT>i<FONT COLOR="#800000">]</FONT> <FONT COLOR="#800000">=</FONT> getImage<FONT COLOR="#800000">(</FONT> getDocumentBase<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">,</FONT>
               <b>basename</b> <FONT COLOR="#800000">+</FONT> i <FONT COLOR="#800000">+</FONT> <FONT COLOR="#FF0000"><b>"."</FONT> <FONT COLOR="#800000">+</FONT> filetype </b><FONT COLOR="#800000">)</FONT><b>.getScaledInstance<FONT COLOR="#800000">(</FONT>
                                           <FONT COLOR="#0000FF">this</FONT>.getSize<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>.width<FONT COLOR="#800000">-</FONT><FONT COLOR="#800080">20</FONT><FONT COLOR="#800000">,</FONT>
                                           <FONT COLOR="#0000FF">this</FONT>.getSize<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>.height<FONT COLOR="#800000">-</FONT><FONT COLOR="#800080">20</FONT><FONT COLOR="#800000">,</FONT>
                                           Image.SCALE_SMOOTH <FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</b></FONT>
            <FONT COLOR="#008000">// ----------------------------------------------------------</FONT>
             <FONT COLOR="#008000">// säg åt MediaTrackern at den skall meddela oss när </FONT>
             <FONT COLOR="#008000">// bilderna är tillgängliga</FONT>
             tracker.addImage<FONT COLOR="#800000">(</FONT> anim<FONT COLOR="#800000">[</FONT>i<FONT COLOR="#800000">]</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">1</FONT> <FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#800000">}</FONT>
     <FONT COLOR="#800000">}</FONT>
    
     <FONT COLOR="#008000">// start behövs om man har implements Runnable</FONT>
     <FONT COLOR="#008000">// dvs om man har ett flertrådigt program</FONT>
     <FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">void</FONT> start<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>
     <FONT COLOR="#800000">{</FONT>
         <FONT COLOR="#008000">// skap en till tråd och sätt den i animator objektet</FONT>
         animator <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">new</FONT> Thread<FONT COLOR="#800000">(</FONT><FONT COLOR="#0000FF">this</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#008000">// starta denna tråd</FONT>
         animator.start<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#800000">}</FONT>
    
     <FONT COLOR="#008000">// stop behövs om man har implements Runnable</FONT>
     <FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">void</FONT> stop<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>
     <FONT COLOR="#800000">{</FONT>
         <FONT COLOR="#008000">// stopp tråden</FONT>
         animator.stop<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#008000">// och döda den</FONT>
         animator <FONT COLOR="#800000">=</FONT> <FONT COLOR="#0000FF">null</FONT><FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#800000">}</FONT>
     <FONT COLOR="#008000">// Kör animeringstråden</FONT>
     <FONT COLOR="#008000">// men vänta först på att alla bilder är laddade</FONT>
     <FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">void</FONT> run<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>
     <FONT COLOR="#800000">{</FONT>
         <FONT COLOR="#008000">// felhanteringen i Java fungerar med try - catch systemet</FONT>
         <FONT COLOR="#008000">// som i C++</FONT>
         <FONT COLOR="#008000">// vi försöker således vänta på att bakgrunden är laddad</FONT>
         <FONT COLOR="#008000">// för att sedan vänta på att de övriga bilderna blivit</FONT>
         <FONT COLOR="#008000">// laddade</FONT>
         <FONT COLOR="#0000FF">try</FONT> <FONT COLOR="#800000">{</FONT>
             tracker.waitForID<FONT COLOR="#800000">(</FONT><FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
             tracker.waitForID<FONT COLOR="#800000">(</FONT><FONT COLOR="#800080">1</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#800000">}</FONT>
         <FONT COLOR="#008000">// någonting har gått fel - avbryt körningen</FONT>
         <FONT COLOR="#0000FF">catch</FONT> <FONT COLOR="#800000">(</FONT>InterruptedException e<FONT COLOR="#800000">)</FONT>
         <FONT COLOR="#800000">{</FONT>
             <FONT COLOR="#0000FF">return</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#800000">}</FONT>
         <FONT COLOR="#008000">// Kolla vilken tråd vi kör</FONT>
         <FONT COLOR="#008000">// och sätt undan denna i en Thread </FONT>
         Thread me <FONT COLOR="#800000">=</FONT> Thread.currentThread<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
        
         <FONT COLOR="#008000">// så länge som den körda tråden är animerings tråden</FONT>
         <FONT COLOR="#008000">// kommer att snurra på så länge som Appleten är igång</FONT>
         <FONT COLOR="#0000FF">while</FONT> <FONT COLOR="#800000">(</FONT>animator <FONT COLOR="#800000">=</FONT><FONT COLOR="#800000">=</FONT> me<FONT COLOR="#800000">)</FONT>
         <FONT COLOR="#800000">{</FONT>
             <FONT COLOR="#008000">// försök stoppa tråden ett antal millisekunder</FONT>
             <FONT COLOR="#0000FF">try</FONT> <FONT COLOR="#800000">{</FONT>
                 <b><FONT COLOR="#008000">// ---------------------------------------------</FONT>
                 <FONT COLOR="#008000">// delvis ändrad</FONT></b>
                 Thread.sleep<FONT COLOR="#800000">(</FONT> <b>delay</b> <FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
                 <b><FONT COLOR="#008000">// ---------------------------------------------</FONT></b>
             <FONT COLOR="#800000">}</FONT>
             <FONT COLOR="#008000">// om det inte gick så avbryter vi loopen</FONT>
             <FONT COLOR="#0000FF">catch</FONT> <FONT COLOR="#800000">(</FONT>InterruptedException e<FONT COLOR="#800000">)</FONT>
             <FONT COLOR="#800000">{</FONT>
                 <FONT COLOR="#0000FF">break</FONT><FONT COLOR="#800000">;</FONT>
             <FONT COLOR="#800000">}</FONT>
            
             <FONT COLOR="#008000">// vi skall öka på index för vilken bild som skall visas</FONT>
             <FONT COLOR="#008000">// För att undvika att någon annan del av programmet</FONT>
             <FONT COLOR="#008000">// försöker göra någonting åt index variabeln så </FONT>
             <FONT COLOR="#008000">// använder vi ordet synchronized, som betyder att </FONT>
             <FONT COLOR="#008000">// denna kod måste bli färdig innan någon annan tråd eller</FONT>
             <FONT COLOR="#008000">// del av programmet får röra index variabeln</FONT>
             synchronized <FONT COLOR="#800000">(</FONT><FONT COLOR="#0000FF">this</FONT><FONT COLOR="#800000">)</FONT>
             <FONT COLOR="#800000">{</FONT>
                 index<FONT COLOR="#800000">+</FONT><FONT COLOR="#800000">+</FONT><FONT COLOR="#800000">;</FONT>
                 <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT>index <FONT COLOR="#800000">></FONT><FONT COLOR="#800000">=</FONT> anim.length<FONT COLOR="#800000">)</FONT>
                 <FONT COLOR="#800000">{</FONT>
                     <FONT COLOR="#008000">// om vi har den sista bilden så tar vi som nästa</FONT>
                     <FONT COLOR="#008000">// den första</FONT>
                     index <FONT COLOR="#800000">=</FONT> <FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">;</FONT>
                 <FONT COLOR="#800000">}</FONT>
             <FONT COLOR="#800000">}</FONT>
             <FONT COLOR="#008000">// rita om Appletten</FONT>
             repaint<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#800000">}</FONT>
     <FONT COLOR="#800000">}</FONT>
    
     <FONT COLOR="#008000">// vid uppdatering så ritar vi om allt</FONT>
     <FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">void</FONT> update<FONT COLOR="#800000">(</FONT>Graphics g<FONT COLOR="#800000">)</FONT>
     <FONT COLOR="#800000">{</FONT>
         paint<FONT COLOR="#800000">(</FONT>g<FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
     <FONT COLOR="#800000">}</FONT>
     <FONT COLOR="#008000">// Rita en röd bakgrund om bilderna inte kunde hämtas</FONT>
     <FONT COLOR="#008000">// I annat fall så ritar vi dit bakgrundsbilden</FONT>
     <FONT COLOR="#0000FF">public</FONT> <FONT COLOR="#0000FF">void</FONT> paint<FONT COLOR="#800000">(</FONT>Graphics g<FONT COLOR="#800000">)</FONT>
     <FONT COLOR="#800000">{</FONT>
         <FONT COLOR="#008000">// har någonting gått fel vid bildhämtningen?</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">(</FONT>tracker.statusAll<FONT COLOR="#800000">(</FONT><FONT COLOR="#0000FF">false</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">&</FONT> MediaTracker.ERRORED<FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">!</FONT><FONT COLOR="#800000">=</FONT> <FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">)</FONT>
         <FONT COLOR="#800000">{</FONT>
             <FONT COLOR="#008000">// röd färg över hela bakgrunden</FONT>
             g.setColor<FONT COLOR="#800000">(</FONT>Color.red<FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
             g.fillRect<FONT COLOR="#800000">(</FONT><FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">,</FONT> getSize<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>.width<FONT COLOR="#800000">,</FONT> getSize<FONT COLOR="#800000">(</FONT><FONT COLOR="#800000">)</FONT>.height<FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
             <FONT COLOR="#008000">// och bort härifrån</FONT>
             <FONT COLOR="#0000FF">return</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#800000">}</FONT>
         <FONT COLOR="#008000">// kom vi hit borde vi ha en bakgrundsbild som vi </FONT>
         <FONT COLOR="#008000">// då kan rita ut</FONT>
         g.drawImage<FONT COLOR="#800000">(</FONT>bg<FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">0</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#0000FF">this</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
        
         <FONT COLOR="#008000">// har vi hunnit ladda alla andra bilder?</FONT>
         <FONT COLOR="#0000FF">if</FONT> <FONT COLOR="#800000">(</FONT>tracker.statusID<FONT COLOR="#800000">(</FONT><FONT COLOR="#800080">1</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#0000FF">false</FONT><FONT COLOR="#800000">)</FONT> <FONT COLOR="#800000">=</FONT><FONT COLOR="#800000">=</FONT> MediaTracker.COMPLETE<FONT COLOR="#800000">)</FONT>
         <FONT COLOR="#800000">{</FONT>
             <FONT COLOR="#008000">// om så är fallet så kan vi rita ut den som </FONT>
             <FONT COLOR="#008000">// är aktuell. Om index är 1 kommer således</FONT>
             <FONT COLOR="#008000">// anim1.gif att ritas</FONT>
             g.drawImage<FONT COLOR="#800000">(</FONT>anim<FONT COLOR="#800000">[</FONT>index<FONT COLOR="#800000">]</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">10</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#800080">10</FONT><FONT COLOR="#800000">,</FONT> <FONT COLOR="#0000FF">this</FONT><FONT COLOR="#800000">)</FONT><FONT COLOR="#800000">;</FONT>
         <FONT COLOR="#800000">}</FONT>
     <FONT COLOR="#800000">}</FONT>
<FONT COLOR="#800000">}</FONT>
</PRE>

<!--#include file="../inc/footer.asp" -->