package test;
import java.awt.Color;
import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class test {
public static void main(String args[]) throws Exception{
JFrame frame=new JFrame("哪吒");
String picPath="E:"+File.separator+"哪吒\\123456.jpg"; //一定要加后缀,如jpg,不然读不到文件
Icon icon=new ImageIcon(picPath);
JLabel lab=null;
lab=new JLabel("重启来了!!!",icon,JLabel.CENTER);
lab.setBackground(Color.YELLOW);
lab.setForeground(Color.RED);
frame.add(lab);
frame.setSize(300,160); //初始窗口大小
frame.setBackground(Color.WHITE);
frame.setLocation(300, 200); //初始窗口位置
frame.setVisible(true);
}
};
运行结果: