这个程序要实现的功能是在鼠标移动的过程中画出轨迹,出了点问题,不知道怎么该,望大家帮忙找找,多谢了import java.awt.event.*;
import java.awt.*;class awt
{
public int nx=0;
public int ny=0;
public static void main(String[] args)
{
awt aa=new awt();
Frame f=new Frame("hello,world");
f.setSize(300,400);
final Panel p=new Panel();
f.add(p);
f.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseMoved(MouseEvent e)
{
int x=e.getX();
int y=e.getY();
System.out.println ("X:"+x+",Y:"+y);
Graphics g=p.getGraphics();
g.drawLine(aa.nx,aa.ny,x,y);
aa.nx=x;aa.ny=y; }
}
);
f.show();
}
}
import java.awt.*;class awt
{
public int nx=0;
public int ny=0;
public static void main(String[] args)
{
awt aa=new awt();
Frame f=new Frame("hello,world");
f.setSize(300,400);
final Panel p=new Panel();
f.add(p);
f.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseMoved(MouseEvent e)
{
int x=e.getX();
int y=e.getY();
System.out.println ("X:"+x+",Y:"+y);
Graphics g=p.getGraphics();
g.drawLine(aa.nx,aa.ny,x,y);
aa.nx=x;aa.ny=y; }
}
);
f.show();
}
}
awt aa=new awt();
改为final awt aa=new awt();2)
f.addMouseMotionListener(new MouseMotionAdapter()
改为 p.addMouseMotionListener(new MouseMotionAdapter()