如题,在JFrame 里。网络地址的图片是怎么添加的呀?!我新手,老是加不上去。谁能给我解解惑么?感激不尽

解决方案 »

  1.   

    我的代码 是这样的 :                JFrame frame = new JFrame();
    frame.setLayout(null);
    frame.setBounds(300, 180, 400, 280);
    ImageIcon image = new ImageIcon("http://www.baidu.com/img/baidu_sylogo1.gif");
    JLabel label = new JLabel(image);
    label.setBounds(80, 30, 250, 120);
    label.setSize(250, 160);
    frame.add(label);
    frame.setDefaultCloseOperation(2);
    label.setVisible(true);
    frame.setVisible(true);
      

  2.   

    试试这样
    URL url = null;
            Image img = null;
            try {
             url = new URL("http://www.baidu.com/img/baidu_sylogo1.gif");
             img = Toolkit.getDefaultToolkit().getImage(url);
            } catch (Exception e) {
             e.printStackTrace();
            }
            JLabel label2 = new JLabel();
            label2.setIcon(new ImageIcon(img));