标题:super.paintComponent(g);的问题
取消只看楼主
sihong20061297
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-10-23
 问题点数:0 回复次数:0 
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);这句好想就没用了    就是说不起作用了  为什么么啊啊
搜索更多相关主题的帖子: super 
2008-10-26 09:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-240651-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.777935 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved