早晨写了个小程序,是想建一个Frame,然后用鼠标在该Frame中点击后会出现一个一个的点。但是程序在编译期间就是无法通过,自己实在是找不出什么问题了,希望大虾们可以抽时间指点一二。
错误提示的内容:
-----------------------------------------------------------
DrawPoint.java:45: 找不到符号
符号: 构造函数 Point(int,int)
位置: 类 Point
Point p = new Point(e.getX(), e.getY());
-----------------------------------------------------------
源程序:
-----------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;public class DrawPoint {
public static void main(String[] args) {
new PointFrame("PointFrame");
}
}class PointFrame extends Frame {
ArrayList points = null;
PointFrame(String title) {
super(title);
points = new ArrayList();
setLayout(null);
setBounds(300, 300, 500, 300);
addMouseListener(new MouseMonitor());
setVisible(true);
} public void paint(Graphics g) {
Iterator i = points.iterator();
Color c = g.getColor();
while(i.hasNext()) {
Point p = (Point)i.next();
g.setColor(Color.orange);
g.fillOval((int)p.x, (int)p.y, 10, 10);
}
g.setColor(c);
}
public void addPoint(Point p) {
points.add(p);
}
}class MouseMonitor extends MouseAdapter {
public void mousePressed(MouseEvent e) {
PointFrame pf = (PointFrame)e.getSource();
Point p = new Point(e.getX(), e.getY());
pf.addPoint(p);
pf.repaint();
}
}
-----------------------------------------------------------
错误提示的内容:
-----------------------------------------------------------
DrawPoint.java:45: 找不到符号
符号: 构造函数 Point(int,int)
位置: 类 Point
Point p = new Point(e.getX(), e.getY());
-----------------------------------------------------------
源程序:
-----------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;public class DrawPoint {
public static void main(String[] args) {
new PointFrame("PointFrame");
}
}class PointFrame extends Frame {
ArrayList points = null;
PointFrame(String title) {
super(title);
points = new ArrayList();
setLayout(null);
setBounds(300, 300, 500, 300);
addMouseListener(new MouseMonitor());
setVisible(true);
} public void paint(Graphics g) {
Iterator i = points.iterator();
Color c = g.getColor();
while(i.hasNext()) {
Point p = (Point)i.next();
g.setColor(Color.orange);
g.fillOval((int)p.x, (int)p.y, 10, 10);
}
g.setColor(c);
}
public void addPoint(Point p) {
points.add(p);
}
}class MouseMonitor extends MouseAdapter {
public void mousePressed(MouseEvent e) {
PointFrame pf = (PointFrame)e.getSource();
Point p = new Point(e.getX(), e.getY());
pf.addPoint(p);
pf.repaint();
}
}
-----------------------------------------------------------
以下是API的内容
-----------------------------------------------------------
构造方法摘要
Point()
在坐标空间的原点 (0,0) 构造并初始化一个点。
Point(int x, int y)
在坐标空间中指定的 (x, y) 位置构造并初始化一个点。
Point(Point p)
构造并初始化一个与指定的 Point 对象具有相同位置的点。
----------------------------------------------------------- -----------------------------------------------------------
Point
public Point(int x,
int y)在坐标空间中指定的 (x, y) 位置构造并初始化一个点。 参数:
x - x 坐标
y - y 坐标
-----------------------------------------------------------