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 没有绘制出文字来?