applet能显示GIF,JPEG,BMP等其他格式的图片。为了在applet中显示图片,你需要使用hics类的drawImage()方法。以下是小编为大家搜索整理的显示图片的方法,欢迎阅读!更多精彩内容请及时关注我们应届毕业生考试网!
如下实例演示了显示图片的所有步骤:
import et.*;
import .*;
import .*;
public class ImageDemo extends Applet
{
private Image image;
private AppletContext context;
public void init()
{
context = ppletContext();
String imageURL = arameter("image");
if(imageURL == null)
{
imageURL = "java.jpg";
}
try
{
URL url = new URL(ocumentBase(), imageURL);
image = mage(url);
}catch(MalformedURLException e)
{
tStackTrace();
// Display in browser status bar
Status("Could not load image!");
}
}
public void paint(Graphics g)
{
Status("Displaying image");
Image(image, 0, 0, 200, 84, null);
String("", 35, 100);
}
}