swing中关于绘图的问题

class NotHelloWorldFrame extends JFrame {
public NotHelloWorldFrame() {
setLayout(new BorderLayout());
setTitle("");
JPanel p = new JPanel();
p.add(new NotHelloWorldComponent());
add(p);
pack();
setLocationRelativeTo(getOwner());
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}

class NotHelloWorldComponent extends JComponent {
public void paintComponent(Graphics g) {
g.drawString("Not a hello,World program", 75, 100);
}

public static void main(String[] args) throws Exception {
    new NotHelloWorldFrame();
}

}
有没人可以帮忙解答下 为什么NotHelloWorldComponent 没有绘制出文字来?

[code="java"]
setTitle("");
JPanel p = new JPanel();

  • p.setLayout(new BorderLayout()); p.add(new NotHelloWorldComponent()); add(p); [/code]

[code="java"]class NotHelloWorldComponent extends JComponent {
public Dimension getPreferredSize(){
return new Dimension(400,300);
}
...
[/code]