当前位置: 代码迷 >> J2SE >> 不知错哪了,请
  详细解决方案

不知错哪了,请

热度:252   发布时间:2016-04-24 16:55:38.0
不知哪里错了,请高手指点
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);
}

}
  相关解决方案