import java.awt.Panel; // För ritning import java.awt.MediaTracker; // Invänta bild import java.awt.Image; // Bild import java.awt.Graphics; // Grafik import java.awt.Toolkit; // Gfkspecial public class rocket_c extends Panel implements Runnable { public rocket_c() { this.xpos = -200; try { this.tracker = new MediaTracker( this ); // Component this.bild = Toolkit.getDefaultToolkit().getImage( ( "rocket.gif") ); // File or URL this.tracker.addImage( this.bild, // Image 0 ); // ID-num } catch ( Exception exc ) { System.out.println( "Fel på ROCKET-datan" ); } } // rocket_c public void start() { this.keep_running = true; Thread rocket_thread = new Thread( this ); // Runnable object rocket_thread.start(); } // start public void run() { try { tracker.waitForID(0); // ID-num this.width = bild.getWidth( this ); // ImageObserver this.height = bild.getHeight( this ); // ImageObserver this.xpos = -this.width; this.xstep = 3; // this.xlast = super.getWidth(); // JDK 1.2 this.xlast = super.getBounds().width; } catch (InterruptedException e) { return; ////////// } while ( this.keep_running ) { try { Thread.sleep( 20 ); // Milliseconds } catch ( InterruptedException exc ) { } this.rubx = this.xpos; this.xpos = this.xpos + this.xstep; if ( this.xpos > this.xlast ) { this.xpos = -this.width; } super.repaint(); } } // run public void update( Graphics gr ) { gr.clearRect( this.rubx, // x 20, // y this.xstep, // width this.height ); // height this.paint( gr ); } // update public void paint( Graphics gr ) { if ( this.keep_running ) { gr.drawImage( this.bild, // Image this.xpos, // x 20, // y this ); // ImageObserver } } // paint private Image bild; private int xpos, rubx, xstep, xlast, height, width; private boolean keep_running; private MediaTracker tracker; } // rocket_c