package elte.java2_utikalauz5.thread; import java.awt.*; import java.awt.image.*; import java.applet.*; import java.io.*; import java.net.*; import javax.imageio.*; /** Egy képet forgat külön szálon.

@link.forrásfájl {@docRoot}/../data/thread/src Logo.java @link.letöltés {@docRoot}/../data/thread Logo.jar @since Java 2 Útikalauz programozóknak */ public class Logo extends Applet implements Runnable { /** Verziószám. */ private final static long serialVersionUID = 15L; private BufferedImage image; // a kép private String filename; // a kép neve private volatile Thread thread = null; // a szál private int row; // sor mutató private int width; // kép szélesség private int height; // kép magasság public void init() { if ((filename = getParameter("imagefile")) == null) System.exit(-1); try { image = ImageIO.read(new URL(getCodeBase(), filename)); } catch (IOException e) { System.exit(-1); } row = 0; width = image.getWidth(); height = image.getHeight(); } public void run() { while (thread == Thread.currentThread()) { row += 4; row %= height; repaint(); try {Thread.sleep(200);} catch (InterruptedException e){} } } public void update(Graphics g) { if (image != null) { g.clearRect(0, 0, width, height ); g.setClip(0, 0, width, row); g.drawImage(image, 0, row - height, null); g.setClip(0, row, width, height - row); g.drawImage(image, 0, row, null); showStatus( "Name:" + filename + ", Size:" + height + "x" + width); } } public void start() { // Az Applet start, ahol if (thread == null) { // ha még nincs szál, thread = new Thread(this); // létrehozzuk thread.start(); // és elindítjuk } } public void stop() { // Az Applet stop, ahol Thread temp = thread; // jelezzük, hogy vége thread = null; // a szálnak temp.interrupt(); } }