- 相关推荐
java显示图片的方法
applet能显示GIF,JPEG,BMP等其他格式的图片。为了在applet中显示图片,你需要使用java.awt.Graphics类的drawImage()方法。以下是小编为大家搜索整理的java显示图片的方法,欢迎阅读!更多精彩内容请及时关注我们应届毕业生考试网!
如下实例演示了显示图片的所有步骤:
import java.applet.*;
import java.awt.*;
import java.net.*;
public class ImageDemo extends Applet
{
private Image image;
private AppletContext context;
public void init()
{
context = this.getAppletContext();
String imageURL = this.getParameter("image");
if(imageURL == null)
{
imageURL = "java.jpg";
}
try
{
URL url = new URL(this.getDocumentBase(), imageURL);
image = context.getImage(url);
}catch(MalformedURLException e)
{
e.printStackTrace();
// Display in browser status bar
context.showStatus("Could not load image!");
}
}
public void paint(Graphics g)
{
context.showStatus("Displaying image");
g.drawImage(image, 0, 0, 200, 84, null);
g.drawString("www.javalicense.com", 35, 100);
}
}
【java显示图片的方法】相关文章:
java上传图片的缩放的方法07-30
用Java处理各类图片的方法08-19
win7图片显示预览图设置方法06-18
word文档几种不显示图片的解决方法08-26
关于java读取文件显示进度条的实现方法11-02
PHP图片上传类带图片显示08-19
网页中图片无法显示09-29
java图片处理功能介绍06-23
java虚方法09-21