创建启动项
package mianban;
public class Mian {
public static void main(String[] args) {
// new Chuang1().init();
// new Tupian();
new Tupian2();
}
}
创建Tupian2类用来加载图片
package mianban;
import javax.swing.*;
import java.awt.*;
public class Tupian2 extends JFrame {
public Tupian2(){
//获取图片(“图片地址”)
ImageIcon imageIcon = new ImageIcon("C:\\Users\\asus\\IdeaProjects\\mianban\\tx.png");
JLabel jLabel = new JLabel(imageIcon);
this.getContentPane().add(jLabel);
//设置窗口位置的大小
setBounds(100,100,500,500);
//设置窗口可见
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
运行即可