如题,代码如下
class MyPanel extends JPanel {
@Override
protected void printComponent(Graphics g) {
super.printComponent(g);//清屏,防止闪屏
this.setBackground(Color.BLACK);
System.out.println("paintComponent已运行");
}
}
class FrameLearn {
public static void main(String[] args){
JFrame frame = new JFrame("Titel");
frame.setBounds(300,300,900,720);
frame.add(new MyPanel());
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
正常来说不应该在我构造MyPanel的时候printComponent就自动运行了吗
不管怎么弄,就是不运行,那句话也无法输出