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();
}
}