我一直在 youtube 上观看有关如何使用 MouceListeners 的视频,以及它的工作视频,但在我的电脑上却没有。这里是代码包Applets;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class MouseListenerTut
extends Applet
implements MouseListener{
private Graphics GG = null;
private void Init(){
this.addMouseListener(this);
}
private int Mx;
private int My;
public void paint(Graphics g){
GG = g.create();
this.setSize(new Dimension(800,600));
}
public void DrawDot(int x, int y){
int r = (int) (Math.random() * 255);
int g = (int) (Math.random() * 255);
int b = (int) (Math.random() * 255);
Color Col = new Color(r,g,b);
GG.setColor(Col);
GG.fillOval(x, y, 10, 10);
}
@Override
public void mouseClicked(MouseEvent e) {
Mx = e.getX();
My = e.getY();
DrawDot(Mx,My);
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
我真的不明白为什么它不起作用,它没有显示任何错误,而且它看起来非常适合他......