我想在Frame中点击鼠标就显示一个圆点。。。不知道哪里错了 望高手指点
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ClickPoint {
public static void main(String[] args) {
new MyFrame("Point");
}
}
class MyFrame extends Frame {
ArrayList points = null;
MyFrame(String name) {
super(name);
setBounds(200,200,500,500);
setLayout(null);
setVisible(true);
this.addMouseListener(new Mon());
}
public void paint(Graphics g) {
Iterator i = points.iterator();
Color c = g.getColor();
while(i.hasNext()) {
Point p = (Point)i.next();
g.setColor(Color.yellow);
g.fillOval(p.x,p.y,5,5);
}
g.setColor(c);
}
public void addPoint(Point p) {
points.add(p);
}
}
class Mon extends MouseAdapter {
public void mousePressed(MouseEvent e) {
MyFrame mf = (MyFrame)e.getSource();
Point p = new Point(e.getX(),e.getY());
mf.addPoint(p);
mf.repaint();
}
}