在Applet中显示图像2025 年 3 月 17 日 | 阅读 1 分钟 Applet主要用于游戏和动画。为此目的需要显示图像。java.awt.Graphics类提供了一个drawImage()方法来显示图像。 drawImage()方法的语法- public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): 用于绘制指定的图像。
|
如何获取Image对象java.applet.Applet类提供了getImage()方法,该方法返回Image对象。语法 |
Applet类中显示图像的其他必需方法- public URL getDocumentBase(): 用于返回Applet嵌入的文档的URL。
- public URL getCodeBase(): 用于返回基本URL。
|
在Applet中显示图像的示例在上面的示例中,使用Graphics类的drawImage()方法来显示图像。drawImage()方法的第4个参数是ImageObserver对象。Component类实现了ImageObserver接口。因此,当前类对象也将被视为ImageObserver,因为Applet类间接扩展了Component类。 |
myapplet.html |