用URL对象封装这个地址,然后用openStream方法获得网络流读取图片数据。
接着你在用swing组件的的g2d对象把这个图画出来。

解决方案 »

  1.   

    ImageIO.read(new URL("http://localhost/code.jsp")
    使用自己的没问题。
    但是使用楼主的URL就是不能读,很奇怪。
      

  2.   

    public class ImageTest { public static void main(String[] args) {
    ImagePanel panel = new ImagePanel(new
    ImageIcon("images/background.png").getImage()); JFrame frame = new JFrame("Hack #1: Create Image-Themed Components");
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true); }
    }
      

  3.   

    public class ImageLabel extends JLabel { public ImageLabel(ImageIcon icon) {
    setSize(icon.getImage().getWidth(null),
       icon.getImage().getHeight(null));
    setIcon(icon);
    setIconTextGap(0);
    setBorder(null);
    setText(null);
    setOpaque(false);
    } }
      

  4.   

    ImageLabel label = new ImageLabel(new ImageIcon("images/reactor.png"));
    label.setLocation(29,37);
    panel.add(label);
      

  5.   

      Graphics g = Graphics.FromImage(bitmap);// 获取图片
      

  6.   

    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.image.BufferedImage;
    import java.io.InputStream;
    import java.net.URL;import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;public class TestImagePanel {
    public static void main(String[] args){
    JFrame frame = new JFrame("Test Image Panel");
    JLabel lbl = new JLabel();
    BufferedImage image = null;
    try {
    URL imageURL = new URL("http://ptlogin2.qq.com/getimage");
    InputStream is = imageURL.openConnection().getInputStream();
    System.out.println();
    image = ImageIO.read(is);
    System.out.println("image is:"+image);
    } catch (Exception e) {
    e.printStackTrace();
    }
    Container c= frame.getContentPane();
    c.setLayout(new FlowLayout());
    c.add(lbl);lbl.setIcon(new ImageIcon(image));
    frame.setBounds(200,100,300,200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    }
      

  7.   

    InputStream is = imageURL.openConnection().getInputStream();
    改成这样
    Connection httpCon = imageURL.openConnection();
    InputStream is = httpCon.getInputStream();
    ...
    image = ImageIO.read(is);
    httpCon.close();