gui

wodeshuangyuzuo 2011-04-30 10:37:33
我调试下面的代码:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class my{
public static void main(String args[]) {
new MyFrame99("drawing...");
}
}

class MyFrame99 extends Frame {
ArrayList<Point> points = null;
MyFrame99(String s) {
super(s);
points = new ArrayList<Point>();
setLayout(null);
setBounds(300,300,400,300);
this.setBackground(new Color(204,204,255));
setVisible(true);
this.addMouseListener(new Monitor());
}

public void paint(Graphics g) {
Iterator<Point> i = points.iterator();
while(i.hasNext()){
Point p = i.next();
g.setColor(Color.BLUE);
g.fillOval(p.x,p.y,10,10);
}
}

public void addPoint(Point p){
points.add(p);
}
}

class Monitor extends MouseAdapter {
public void mousePressed(MouseEvent e) {
MyFrame99 f = (MyFrame99)e.getSource();
f.addPoint(new Point(e.getX(),e.getY()));
f.repaint();
}
}
但是出错了 提示如下
F:\>javac my.java
my.java:27: x 可以在 Point 中访问 private
g.fillOval(p.x,p.y,10,10);
^
my.java:27: y 可以在 Point 中访问 private
g.fillOval(p.x,p.y,10,10);
^
my.java:27: 无法将 java.awt.Graphics 中的 fillOval(int,int,int,int) 应用于 (doub
le,double,int,int)
g.fillOval(p.x,p.y,10,10);
^请问是怎么没事谢谢
...全文
76 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wodeshuangyuzuo 2011-05-01
  • 打赏
  • 举报
回复
谁能给个解释,谢谢!
snaillxc 2011-05-01
  • 打赏
  • 举报
回复
fillOval(int,int,int,int)所需的四个参数都是int型的 而你的p.x p.y是double型的 也就是所传的参数类型不对,g.fillOval(p.x,p.y,10,10);这一句应该这样写:g.fillOval((int)p.x,(int)p.y,10,10);
wodeshuangyuzuo 2011-04-30
  • 打赏
  • 举报
回复
你的方法我明白,但是定义了一个Ponit的p,所以p.x不就是获得他的坐标吗?
Jeelon 2011-04-30
  • 打赏
  • 举报
回复
你程序里面用的 p.x也就是 我写的x p.y就是我写的y
Jeelon 2011-04-30
  • 打赏
  • 举报
回复
point里面要么写两个参数(x,y)
要么在下下面引用的时候 这一写:
int x = p.getX();
int y = p.getY();

然后在调用画图方法 就可以了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧