在JFrame中使用jlabel添加圖片


public class Demo extends JFrame{
    public Demo() {
        // TODO Auto-generated constructor stub
    setBounds(100,100,500,350);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container container = getContentPane() ;
    JLabel l = new JLabel("這是一個展示圖片的標簽");
    //URL url = Demo.class.getResource("huasacm.png");
    //Icon icon = new ImageIcon(url);
    Icon icon = new ImageIcon("src/huasacm.png");
    l.setIcon(icon);
    l.setSize(20,20);
    container.add(l);
    setVisible(true);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Demo();
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM