日期:2014-05-20  浏览次数:20609 次

初学java gui,问个有关Component的问题
import   java.awt.*;
class   TestComponent   extends   Component  
{
public   static   void   main(String[]   args)  
{
TestComponent   tp   =   new   TestComponent();
tp.setBackground(Color.green);
tp.setSize(300,300);
tp.setVisible(true);
}
}

我继承了一个容器类,编译没问题,为什么运行不能显示我创建的容器呢?

------解决方案--------------------
回答一下LZ,
这个容器本来就是不可见的~
它是最底层的容器,
不过你可以往上添加一个JFrame,
这样你就可以看见了!
不过看到的是这个Frame
那个Component还是看不了的~