0

如何从小程序中的文件中绘制图像?

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

/*
    <applet code = "DisplayImageExample" width = 500 height = 300>
            <param name = "Image1" value = "one.jpg">
            <param name = "Image2" value = "two.jpg">
    </applet>
*/

public class NewApplet extends Applet
{
    Image img1, img2;

    public void init(){

            img1 = getImage(getDocumentBase(), getParameter("aw.jpg"));
            img2 = getImage(getDocumentBase(), getParameter("sd"));
    }

    public void paint(Graphics g){

            //display an image using drwaImage method of Graphics class.
            g.drawImage(img1, 1,5,this);
            g.drawImage(img2, 100,100,this);
    }

}

我是否正确设置了图像路径?

4

1 回答 1

1

您需要使用 applet 参数中的参数键名称,而不是它们的实际值:

img1 = getImage(getDocumentBase(), getParameter("Image1"));
img2 = getImage(getDocumentBase(), getParameter("Image2"));
于 2013-03-10T16:00:57.060 回答