mouse监控的问题 ,求助
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MouseTest extends JApplet{
boolean flag=false;
int x=20; int y=20;
Container cp;
public void init(){
cp=getContentPane();
cp.addMouseListener(new MouseAdapter){
public void mousePressed(MouseEvent e){
flag=true;
}
public void mouseReleased(MouseEvent e){
x=e.getX();
y=e.getY();
flag=false;
repaint();}
}
addMouseListener(new MouseMotionAdapter){
public void mouseDragged(MouseEvent ee){
if(flag){
x=ee.getX();
y=ee.getY();
repaint();
}
}
});
}//end init()
public void paint(Graphics g){
super.paint(g);
g.drawString( "心随你动 ",x,y);
}
}
一堆的错误,召唤达人帮忙看一下,感激不尽!!
------解决方案-------------------- import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JApplet;
public class MouseTest extends JApplet {
boolean flag = false;
int x = 20;
int y = 20;
Container cp;
public void init(){
cp=getContentPane();
cp.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
flag=true;
}
public void mouseReleased(MouseEvent e){
x=e.getX();
y=e.getY();
flag=false;
repaint();}
});
cp.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent ee){
if(flag){
x=ee.getX();
y=ee.getY();
repaint();
}
}
});
}// end init()
public void paint(Graphics g) {
super.paint(g);
g.drawString( "心随你动 ", x, y);
}
}
------解决方案--------------------你自己看下MouseEvent的AOI吧.
哈哈