奇了个怪了,没什么大问题。你在cmd里编译试试
实在不行,加我QQ:656098987,帮你远程看看
代码可以试试这么写import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class App12_1 extends JFrame {
JLabel lab;
public App12_1() {
/* 实例化组件 */
lab = new JLabel("我是一个标签");
/* 设置布局 */
/* 位置放置 */
/* 添加组件 */
this.add(lab);
/* 窗体设置 */
// 设置图标
this.setTitle("这是一个Swing程序");
Image im = (new ImageIcon("中国心.jpg")).getImage();
this.setIconImage(im);
// 窗体大小
int width = 250;
int height = 140;
this.setSize(width, height);
// 屏幕的大小
int swidth = (int) Toolkit.getDefaultToolkit().getScreenSize()
.getWidth();
int sheight = (int) Toolkit.getDefaultToolkit().getScreenSize()
.getHeight();
// 设置位置(居中显示)
this.setLocation((swidth - width) / 2, (sheight - height) / 2);
this.setBackground(Color.YELLOW);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new App12_1();
}
}