我为什么不能运行Swing的程序

以下程序编译可以通过,但不能运行

import java.awt.Container;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
 

class TestJframe{
    public static void main(String[] args)throws Exception{ 
        JFrame jf = new JFrame("My Test");
        Container c = jf.getContentPane();
        c.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
        JLabel greet = new JLabel("Hello,World!");
        JLabel bye = new JLabel("Bye,World!");
        bye.setBackground(Color.blue);
        bye.setOpaque(true);
        c.add(greet);
        c.add(bye);
        c.setBackground(Color.green);
        jf.setSize(200,100);
        jf.setLocation(400,200);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
  }
}

发布了28 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wodetongnian/article/details/6370529