问题描述
我用Frame建立一个窗口在里面画圆点,先用ArrayList容器装Point可以画出很多个,后来用变量代替就只能画一个我很纳闷这是为什么?代码如下注释部分是先用ArrayList容器的代码。importjava.awt.*;importjava.awt.event.*;importjava.util.*;publicclassMyMouseAdapter{publicstaticvoidmain(String[]args){MyFramemf=newMyFrame("Test");}}classMyFrameextendsFrame{//ArrayListpoints=null;Pointp;MyFrame(Strings){super(s);//points=newArrayList();setBounds(300,300,400,500);setVisible(true);addMouseListener(newMonitor());}publicvoidpaint(Graphicsg){//Iteratori=points.iterator();//while(i.hasNext())//{//Pointp=(Point)i.next();//g.setColor(Color.BLUE);//g.fillOval(p.x,p.y,10,10);//}g.setColor(Color.BLUE);g.fillOval(p.x,p.y,10,10);}//publicvoidaddPoint(Pointp)//{//points.add(p);//}}classMonitorextendsMouseAdapter{publicvoidmouseReleased(MouseEvente){MyFramemf=(MyFrame)e.getSource();//mf.addPoint(newPoint(e.getX(),e.getY()));mf.p=newPoint(e.getX(),e.getY());mf.repaint();}}
解决方案
解决方案二:
该回复于2014-09-22 08:43:40被版主删除