Internet Start Page  TOP  
 Road of Developers
 
 


DownLoad Animation.lzh(ソースコード付き)


//////////////////////////////////////////////////////////////////////////////
// AnimationMovieアプレット / I-ichirow Suzuki
// movie.java
// 
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
//----------------------------------------------------------------------------
public class movie extends Applet
    implements Runnable
{
    Image imgs[];
    int nimgs;
    int timeout;
    Thread myThread;
    String dir;
    int counter;
    int px;
    int py;
    int pp;
    int pox[];
    int poy[];
    Image offs;
    int factor;
    Graphics grf;
    boolean fwd;
    boolean init1;
    boolean iswait;
    MediaTracker tracker;
	//--------------------------------------------------
    public movie()
    {
        timeout = 200;
        fwd = true;
        init1 = true;
    }
	//--------------------------------------------------
    public void init()
    {
        String s1 = "jpg";
        String s = getParameter("file");
        dir = s == null ? "./img" : s;
        s = getParameter("speed");
        timeout = 1000 / (s != null ? Integer.valueOf(s).intValue() : 10);
        s = getParameter("nimgs");
        nimgs = s != null ? Integer.valueOf(s).intValue() : 16;
        s = getParameter("type");
        if(s != null)
            s1 = s;
        s = getParameter("zoom");
        if(s == null)
            factor = 1;
        else
            factor = Integer.valueOf(s).intValue();
        tracker = new MediaTracker(this);
        offs = createImage(size().width, size().height);
        grf = offs.getGraphics();
        imgs = new Image[nimgs];
        for(int i = 0; i < nimgs; i++)
        {
            imgs[i] = getImage(getDocumentBase(), dir + (i + 1) + "." + s1);
            tracker.addImage(imgs[i], 0);
        }
        py = size().height - 16;
        px = 32;
        pp = size().width - 32 - 6;
        pox = new int[4];
        poy = new int[4];
        pox[0] = 10;
        poy[0] = py + 7;
        pox[1] = 6;
        poy[1] = py + 3;
        pox[2] = 6;
        poy[2] = py + 11;
    }
	//--------------------------------------------------
    public void start()
    {
        if(myThread == null)
        {
            myThread = new Thread(this);
            myThread.start();
        }
    }
	//--------------------------------------------------
	public void stop()
    {
        if(myThread != null)
        {
            myThread.stop();
            myThread = null;
        }
    }
	//--------------------------------------------------
    public void run()
    {
        do
        {
            do
                try
                {
                    Thread.currentThread();
                    Thread.sleep(timeout);
                }
                catch(InterruptedException _ex) { }
            while(iswait);
            repaint();
        } while(true);
    }
	//--------------------------------------------------
    public void update(Graphics g)
    {
        paint(g);
    }
	//--------------------------------------------------
    public void paint(Graphics g)
    {
        if(init1)
        {
            init1 = false;
            g.setColor(Color.yellow);
            g.fillRect(0, 0, size().width, size().height);
            g.setColor(Color.black);
            g.drawString("Loading..", 5, 20);
            tracker.checkID(0, true);
            try
            {
                tracker.waitForID(0);
            }
            catch(InterruptedException _ex)
            {
                return;
            }
            g.clearRect(0, 0, size().width, size().height);
        }
        int i = (pp * counter) / (nimgs - 1);
        grf.setColor(Color.lightGray);
        grf.fillRect(0, 0, size().width, size().height);
        grf.fill3DRect(0, py, 15, 15, true);
        grf.fill3DRect(16, py, 15, 15, true);
        grf.draw3DRect(px, py, pp + 5, 14, true);
        grf.draw3DRect(0, 0, size().width - 1, py - 1, true);
        grf.setColor(Color.white);
        grf.fillRect(px + 3 + i, py + 3, pp - i, 9);
        grf.setColor(Color.darkGray);
        grf.fillRect(px + 3, py + 3, i, 9);
        grf.fillPolygon(pox, poy, 3);
        grf.fillRect(20, py + 4, 7, 7);
        if(factor == 1)
            grf.drawImage(imgs[counter], 1, 1, this);
        else
            grf.drawImage(imgs[counter], 1, 1, imgs[counter].getWidth(this) * factor, imgs[counter].getHeight(this) * factor, this);
        g.drawImage(offs, 0, 0, this);
        if(fwd)
        {
            counter++;
            if(counter >= nimgs)
            {
                counter = nimgs - 1;
                fwd = false;
            }
        } else
        {
            counter--;
            if(counter < 0)
            {
                counter = 0;
                fwd = true;
            }
        }
    }
	//--------------------------------------------------
    public boolean mouseExit(Event event, int i, int j)
    {
        getAppletContext().showStatus("");
        return true;
    }
	//--------------------------------------------------
    public boolean mouseUp(Event event, int i, int j)
    {
        if(i >= 0 && i <= 15 && j >= py)
            iswait = false;
        if(i >= 16 && i <= 31 && j >= py)
            iswait = true;
        if(j <= py)
            iswait = !iswait;
        repaint();
        return true;
    }
	//--------------------------------------------------
    public boolean mouseDown(Event event, int i, int j)
    {
        if(i >= 0 && i <= 15 && j >= py)
        {
            getGraphics().setColor(Color.lightGray);
            getGraphics().fillRect(0, py, 15, 15);
        }
        if(i >= 16 && i <= 31 && j >= py)
        {
            getGraphics().setColor(Color.lightGray);
            getGraphics().fillRect(16, py, 15, 15);
        }
        return true;
    }
	//--------------------------------------------------
    public boolean mouseDrag(Event event, int i, int j)
    {
        if(i >= px && i <= px + pp && j >= py)
        {
            iswait = true;
            counter = ((i - px) * nimgs) / pp;
            if(counter >= nimgs)
                counter = nimgs - 1;
            if(counter < 0)
                counter = 0;
            repaint();
        }
        return true;
    }
	//--------------------------------------------------
    public boolean mouseMove(Event event, int i, int j)
    {
        if(i >= 0 && i <= 15 && j >= py)
            getAppletContext().showStatus("Start movie");
        else
        if(i >= 16 && i <= 31 && j >= py)
            getAppletContext().showStatus("Stop movie");
        else
        if(i >= px && i <= px + pp && j >= py && iswait)
            getAppletContext().showStatus("Frame control");
        else
            getAppletContext().showStatus("");
        return true;
    }
}

インターネットスタートページ 鈴木維一郎 石橋三重子
         
               
                   


©2000 kg-group Inc.