使用java applet加载图像 [英] Load image with java applet

查看:78
本文介绍了使用java applet加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从文件加载图像的LoadImage类



小程序窗口出现但是图像没有加载,还有什么类型的图像是可加载的jpeg,gif或png的



我的尝试:



Here is the LoadImage class to load image from file

the applet window appears but the image doesnt loads, also what type of image are loadable jpegs, gifs or png's

What I have tried:

package DrawImage;

   import java.net.*;
   import java.awt.*;

   public class LoadImage extends java.applet.Applet
   {
       Image uc  ;
       URL base;
       MediaTracker mt;

       public void init()
       {
           mt = new MediaTracker(this);
           try{
                   base = getDocumentBase();
                   }catch(Exception e){}

           uc = getImage(base, "aerodynamics.gif");
           mt.addImage(uc,1);

           try{
           mt.waitForAll();
           }catch(InterruptedException e){}
   }

       public void paint(Graphics g)
   {
           g.drawImage(uc, 45  , 45, Color.yellow, this);
       }
  }

推荐答案

参见Image(Java Platform SE 7) [ ^ ]。


这篇关于使用java applet加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆