getImagepublic Image getImage(URL url)
Returns an Image object that can then be painted on the screen. The url that is passed as an argument must specify an absolute URL.This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen.Parameters:url - an absolute URL giving the location of the image.getImage( "http://www.sina.com.cn...........gif" );

解决方案 »

  1.   

    楼主啊,你有没有搞错啊,你的程序好多漏洞啊你要完成这个在网上获取资料,你首先要传入 Java.net 包啊你用了this 怎么又不用 Runnable ?我也是菜,自己的意见,错了的话,各位大侠不要用臭鸡蛋打我
      

  2.   

    Image picture;
    public void init(){
       //URL u = new URL("");
       picture =getImage( "http://sina.com/abc.gif" );
      }
      public void paint(Graphics g){
       g.drawImage(picture,25,25,this);
      }
    }
      

  3.   

    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import java.net.*;
    public class HwImage extends Applet{
    URL u = new URL("");
    //("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
    Image picture;
    public void init(){
      
       picture =getImage("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
      }
      public void paint(Graphics g){
       g.drawImage(picture,350,350,this);
      }}
    这样还是错啊,我还没好好学applet,但明天要交了
      

  4.   

    //我试过的,好像是applet无法显示而已,方法没有错,只是显示的问题
    import java.awt.*;
    import java.applet.Applet;
    import java.applet.*;
    import java.util.*; 
    import java.net.*;public class HwImage extends Applet{
    //URL u = new URL("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
    //("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
            public Image picture;
            
    public void init(){
        try{
    URL u = new URL("http://www.pconline.com.cn/mobile/show/images/picpath/030623_530_135_01.jpg");
      
           picture =getToolkit().getImage(u);
           }catch(Exception e){}
      
        }
     
     
      public void paint(Graphics g){
     
       g.drawImage(picture,1,1,this);
      }      public static void main(String args[]){
           Frame f=new Frame("GetImage");
           //f.addWindowListener(new WindowClose(f,true));
           HwImage myApplet=new HwImage();
           f.add(myApplet);
           myApplet.init();
           f.setSize(100,100);
           f.setVisible(true);
           myApplet.start();
          
           }}
      

  5.   

    以上我程序我自己试过的,可以显示图片的
    但是applet要装载在Frame 上  呵呵,我也是翻书才发现的 呵呵
      

  6.   

    如果图片无法显示,可以换成其他URL的地址的图片
      

  7.   

    还是有问题,
    编译成HwImage.java,运行,可以显示图片
    用applet则没图片???~!!!!
    怎么回事?
      

  8.   

    applet有权限的问题
    刚才我测试的时候······
    Frame则没有权限的问题
      

  9.   

    那应该怎么改
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import java.applet.*;
    import java.util.*;
    import java.net.*;public class HwImage extends Applet{
    //URL u = new URL("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
    //("http://joke.tom.com/img/assets/1/gaoxiao_80_629.jpg");
            public Image picture; public void init(){
        try{
    URL u = new URL("http://www.pconline.com.cn/mobile/show/images/picpath/030623_530_135_01.jpg");        picture =getToolkit().getImage(u);
           }catch(Exception e){}     }
      public void paint(Graphics g){    g.drawImage(picture,1,1,this);
      }
       public static void main(String args[]){
        Frame f=new Frame("GetImage");       Toolkit tk=Toolkit.getDefaultToolkit();
    Dimension d=tk.getScreenSize();
    int screenHeight=d.height;
    int screenWidth=d.width;
    f.setSize(400,300);
    f.setLocation(screenWidth/4,screenHeight/4);
    f.setResizable(false);
    f.setVisible(true);       f.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });
           HwImage myApplet=new HwImage();
           f.add(myApplet);
           myApplet.init();
           myApplet.start();
           f.show();
    }
    }
      

  10.   

    applet的权限,出于安全的问题,在网络的下载的Applet不允许访问本地的文件,更不能存取服务器上的文件,所以applet....下不了上面的文件的
      

  11.   

    那这个题不是有问题?
    有什么好的解决方法吗?编写一个Applet小程序,用来动态获取网络上的各种资源,实现方法是在Applet小程序中加入一个线程,每隔一定的时间自动地到指定的网络站点上读取最新的内容。