有人会知道为什么不调用我的 PF 类的函数 paintComponent 吗?
public class Fenetre
{
private JFrame jframe;
public Fenetre()
{
jframe = new JFrame(" works");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setLayout(new BorderLayout());
jframe.setLocationRelativeTo(null);
jframe.setContentPane(new P());
jframe.pack();
jframe.setVisible(true);
}
public class P extends JComponent
{
public P()
{
this.setPreferredSize(new Dimension(WI,HI));
this.add(new PF());
}
public class PA extends JComponent
{
@Override protected void paintComponent(Graphics g) {
DrawX(g);
DrawY(g);
}
public void DrawX(Graphics g)
{
\* .. */
}
public void DrawY(Graphics g)
{
\* ..*/
}
}
public class PF extends PA
{
@Override protected void paintComponent(Graphics g) {
super.paintComponent(g);
drawS(g);
drawT(g);
}
public void drawS(Graphics g)
{ \* .. */
}
public void drawT(Graphics g)
{
\* ... */
}
}
当我在 PF 构造函数中设置 setSize 函数时,它可以工作,但是 setPreferredSize 也可以工作,但不允许类 PF 可调整大小,也就是说,如果我调整 Jframe 的大小,PF 绘制不会调整大小..
希望有人可以帮助我,谢谢。