问题描述
主要问题是,paintComponent这个函数不知道是怎么跑进去的,该怎么理解?望不吝赐教importjava.awt.*;importjava.awt.geom.*;importjavax.swing.*;publicclassMapextendsJFrame{publicMap(){super("Map");setSize(350,350);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);MapPanemap=newMapPane();add(map);setVisible(true);}publicstaticvoidmain(String[]arguments){Mapframe=newMap();}}classMapPaneextendsJPanel{publicvoidpaintComponent(Graphicscomp){Graphics2Dcomp2D=(Graphics2D)comp;comp2D.setColor(Color.blue);comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);Rectangle2D.Floatbackground=newRectangle2D.Float(0F,0F,(float)getSize().width,(float)getSize().height);comp2D.fill(background);//Drawwavescomp2D.setColor(Color.white);BasicStrokepen=newBasicStroke(2F,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND);comp2D.setStroke(pen);for(intax=0;ax<340;ax+=10)for(intay=0;ay<340;ay+=10){Arc2D.Floatwave=newArc2D.Float(ax,ay,10,10,0,-180,Arc2D.OPEN);comp2D.draw(wave);}//DrawFloridaGradientPaintgp=newGradientPaint(0F,0F,Color.green,350F,350F,Color.orange,true);comp2D.setPaint(gp);GeneralPathfl=newGeneralPath();fl.moveTo(10F,12F);fl.lineTo(234F,15F);fl.lineTo(253F,25F);fl.lineTo(12F,37F);fl.closePath();comp2D.fill(fl);//Drawovalscomp2D.setColor(Color.black);BasicStrokepen2=newBasicStroke();comp2D.setStroke(pen2);Ellipse2D.Floate1=newEllipse2D.Float(235,140,15,15);Ellipse2D.Floate2=newEllipse2D.Float(225,130,15,15);Ellipse2D.Floate3=newEllipse2D.Float(245,130,15,15);comp2D.fill(e1);comp2D.fill(e2);comp2D.fill(e3);}}
解决方案
解决方案二:
系统调用的,程序员不会直接调用这个函数。
解决方案三:
引用1楼Inhibitory的回复:
系统调用的,程序员不会直接调用这个函数。
原来如此……竟忘了先百度。多谢