super.paintComponent(g);的问题
import java.awt.*; import javax.swing.*;
public class MMan extends JFrame
{
public MMan()
{
setTitle("MatchStick Man");
getContentPane().add(new MManPanel());
}
public static void main(String[] args)
{
MMan frame = new MMan();
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.setVisible(true);
}
}
class MManPanel extends JPanel
{
public void paintComponent(Graphics g) //you mei you component dou meiguan xi de
{
super.paintComponent(g);
this.setBackground(Color.green);
g.setColor(Color.RED);
g.drawOval(50,50,50,50);
g.drawLine(75,100,75,200);
g.drawLine(15,125,135,125);
g.drawLine(75,200,15,300);
g.drawLine(75,200,135,300);
g.setColor(Color.BLUE);
g.drawOval(250,50,50,50);
g.drawLine(275,100,275,200);
g.drawLine(210,125,335,125);
g.drawLine(275,200,210,300);
g.drawLine(275,200,335,300);
g.setColor(Color.BLACK);
g.drawOval(450,50,50,50);
g.drawLine(475,100,475,200);
g.drawLine(410,125,535,125);
g.drawLine(475,200,410,300);
g.drawLine(475,200,535,300);
}
}
问一下这里的super.paintComponent(g);有什么用啊 如果没有的话 this.setBackground(Color.green);这句好想就没用了 就是说不起作用了 为什么么啊啊