如何修复小程序查看器,因为它不起作用

时间:2019-03-27 01:21:40

标签: java applet awt event-dispatch-thread

我尝试运行我的applet代码,但无法正常工作。窗户保持白色。我使用Java 10版本。我该如何解决错误?问题将是版本的类型。

我的代码: ...

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

public class StickAnimaiton1 extends Applet {
    Image img1;  //will contain images to be displayed

    void drawImageWithDelay(Graphics g,Image img,int xpos, int ypos, int delay)
    // g       = the Graphic object
    // img     = Image object containing the image to be displayed
    // xpos    = x position where the image will be displayed
    // ypos    = y position where the image will be displayed
    // delayed = delay in milliseconds that will be waited
    //           after displaying the image
    {
        g.drawImage(img, xpos,ypos,200,100,this);

        //the next code implements the delay
        try{
            Thread.sleep(delay);
        }
        catch(InterruptedException e)
        {
        }
    }

    public void init() {
        setBackground(Color.white);
    }

    public void start() {
    }

    public void paint(Graphics g) {
        for (int j=0; j<5; j++)
        {
            for (int i=1; i<=11; i++)   //11 frames
            {
                g.clearRect(0,0,400,200); //erase previous image
                if (i < 10)
                {
                    img1 = getImage(getCodeBase(),"pacman0" + i + ".png");
                }
//                else
//                {
//                    img1 = getImage(getCodeBase(),"pacman" + i + ".png");
//                }
                drawImageWithDelay(g,img1,0,0,300);  //call draw function
            }
        }
    }
}

...

如果有人可以帮助我,那将非常有帮助。

0 个答案:

没有答案