编写一个Applet响应鼠标事件,用户可以通过拖动鼠标在Applet中画出蓝色的圆点

//
//
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class MouseEventDemo extends Applet {
	public void init(){
		addMouseListener(new CircleListener());
		setForeground(Color.blue);
		setBackground(Color.white);
	}
}
class CircleListener extends MouseAdapter {
	private int radius = 20;
	public void mousePressed(MouseEvent e) {
		Applet app = (Applet)e.getSource();
		Graphics g = app.getGraphics();
		g.fillOval(e.getX()-radius, e.getY()-radius, 2*radius, 2*radius);
	}
}

你可能感兴趣的:(Java,applet,class,import)