日期:2014-05-20  浏览次数:20657 次

不知哪里错了,请高手指点
import   java.awt.*;
import   java.awt.event.*;
import   java.applet.*;

public   class   Mouseevent   extends   Applet   implements   MouseListener{

String   msg= "来点我 ";
public   void   init(){
addMouseListener(this);
}
public   boolean   mouseEntered(Event   e){
msg= "鼠标进来 ";
repaint();
return   true;
}
public   boolean   mouseExited(Event   e){
msg= "鼠标离开 ";
repaint();
return   true;
}
public   void   mouseClicked(MouseEvent   e){}
public   void   mouseReleased(MouseEvent   e){}
public   void   mousePressed(MouseEvent   e){}
public   void   paint(Graphics   g){
g.setColor(Color.red);
g.setFont(new   Font( "Dialogs ",0,40));
g.drawString(msg,   4,   60);
}

}


------解决方案--------------------
public void mouseEntered(MouseEvent e) {
msg = "鼠标进来 ";
repaint();
}

public void mouseExited(MouseEvent e) {
msg = "鼠标离开 ";
repaint();
}

Event--> MouseEvent
返回值为void
------解决方案--------------------
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Test extends Applet implements MouseListener{

String msg= "来点我 ";
public void init(){
addMouseListener(this);
}
public void mouseEntered(MouseEvent e){
msg= "鼠标进来 ";
repaint();
//return true;
}
public void mouseExited(MouseEvent e){
msg= "鼠标离开 ";
repaint();
//return true;
}
public void mouseClicked(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void paint(Graphics g){
g.setColor(Color.red);
g.setFont(new Font( "Dialogs ",0,40));
g.drawString(msg, 4, 60);
}

}