请问java高手,如何在窗口中导入图片,谢谢谢谢!

解决方案 »

  1.   

    只要在窗口中得到图片很容易,将图片加到JLabel然后将JLabel加到JFrame就行了.
    下面给出简洁代码,以资参考。这类问题LZ应该都看看书中swing章节,自行解决,这样才能更快提高.import javax.swing.*;
    import java.net.*;public MyFrame extends JFrame{
      public MyFrame(String title){
        super(title);
        setLayout(null);
        JLabel jl = new JLabel();
        URL url = MyFrame.class.getResource("你的图片全名.jpg"); //图片和主类放到一个包内
        Icon icon = new ImageIcon(url);
        jl.setIcon(icon);
        jl.setVisible(true);
        add(jl);
        pack();
     }
      public static void main(String[] args){
        new MyFrame();
     }
    }
      

  2.   

    不知道你的导入是啥
    楼上说的是设置图标样要导入导入到页面中的话 就是要用到g.drawImage()方法
      

  3.   

    不知道你要导入什么图片,这是其中的一种,    public static void main(String[] arge){        ImageIcon ioc = new ImageIcon("D:\\2008102307425359990100.jpg");
            JScrollPane panel = new JScrollPane();
            panel.getViewport().add(new JLabel(ioc),BorderLayout.CENTER);
            Dimension dim = panel.getPreferredSize();
            dim.setSize(600, 600);
            panel.setPreferredSize(dim);        JFrame internal = new JFrame ();
            internal.setSize(600,600);        internal.setContentPane(panel);
            internal.setVisible(true);
        }
      

  4.   

      public static void main(String[] arge){  ImageIcon ioc = new ImageIcon("D:\\2008102307425359990100.jpg");
      JScrollPane panel = new JScrollPane();
      panel.getViewport().add(new JLabel(ioc),BorderLayout.CENTER);
      Dimension dim = panel.getPreferredSize();
      dim.setSize(600, 600);
      panel.setPreferredSize(dim);  JFrame internal = new JFrame ();
      internal.setSize(600,600);  internal.setContentPane(panel);
      internal.setVisible(true);
      } 
     好!!!