import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;public class try1
{
public static void main(String[] args)
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class DrawFrame extends JFrame
{
public DrawFrame()
{
setTitle("JapaneseFlag");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); DrawComponent component = new DrawComponent();
add(component);
}
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 400;
}
class DrawComponent extends JComponent
{
Graphics2D g2;
Ellipse2D circle = new Ellipse2D.Double(x,y,100,100); public void paintComponent(Graphics g)
{
super.paintComponent(g);
g2 = (Graphics2D)g;
g2.draw(circle);
x+=10;
System.out.println("x="+x);
}

private static double x = 100;
private static double y = 150;}这个程序没什么,开一个窗口,画个圆,但奇怪的是红色部分输出是x=110 x=120,好像paintComponent方法被调用两次,这是怎么回事呢?