其他分享
首页 > 其他分享> > 图片Icon(ImageIcon)

图片Icon(ImageIcon)

作者:互联网

package cn.rushangw.lesson04;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ImageIconDemo extends JFrame{

public ImageIconDemo(){
//获取图片的地址
JLabel jLabel = new JLabel("ImageIcon");
URL url = ImageIconDemo.class.getResource("lADPD3W5ONBVGtTNBDjNB4A_1920_1080.jpg");

ImageIcon imageIcon = new ImageIcon(url);

jLabel.setIcon(imageIcon);
jLabel.setHorizontalAlignment(SwingConstants.CENTER);

Container container = getContentPane();
container.add(jLabel);

setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setBounds(20,20,500,500);

}

public static void main(String[] args) {
new ImageIconDemo();
}
}

标签:ImageIcon,new,ImageIconDemo,import,jLabel,Icon,public,图片
来源: https://www.cnblogs.com/nigustudent/p/14810075.html