| 目次| 1234567891011121314
| 資料| 予定| 課題| 宿題|

プログラムリスト

Main.java

public class Main {
    public static void main(String args[]) {
        System.out.println("こんにちは.");
        System.out.println("Hello, Java!");
    }
}

Main.java(変更版)

public class Main {
    public static void main(String args[]) {
        System.out.print("こんにちは.");
        System.out.println("Hello, Java!");
    }
}

SimpleAnimation.java

import java.applet.Applet;
import java.awt.*;

public class SimpleAnimation extends Applet implements Runnable {
    String imagedir;
    String imageprefix;
    int last;
    Image images[];
    int current;
    Thread thread;

    public void init() {
        String s;
        s = getParameter("imagedir");
        if (s != null) imagedir = s;
        s = getParameter("imageprefix");
        if (s != null) imageprefix = s;
        s = getParameter("last");
        if (s != null) last = Integer.parseInt(s);

        current = 0;
        images = new Image[last];
        for (int i = 0; i < last; i++) {
            images[i] =
                getImage(getDocumentBase(),
                    imagedir + "/" + imageprefix + (i+1) + ".gif");
        }
    }

    public void start() {
        if (thread == null) {
            thread = new Thread(this);
            thread.start();
        }
    }

    public void paint(Graphics g) {
        g.drawImage(images[current], 0, 0, this);
    }

    public void run() {
        while(true) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                break;
            }
            current++;
            if (current == last) current = 0;
            repaint();
        }
    }
}

SimpleAnimation.html

<HTML>
<HEAD>
<TITLE>Applet Sample</TITLE>
</HEAD>
<BODY>
<H1> アニメーション </H1>

<APPLET CODE="SimpleAnimation.class" WIDTH=100 HEIGHT=100>
<PARAM NAME="imagedir"    VALUE="images">
<PARAM NAME="imageprefix" VALUE="snow">
<PARAM NAME="last"        VALUE="6">
</APPLET>

</BODY>
</HTML>

| 目次| 1234567891011121314
| 資料| 予定| 課題| 宿題|