java鼠标监听器画图+点击X关闭窗口

package awt;
import java.awt.*;
import java.util.*;
import java.awt.event.*;

import org.omg.CORBA.PUBLIC_MEMBER;
public class MouseFrame extends Frame{
	ArrayList Poi = new ArrayList();//将所有的圆点装起来
	MouseFrame (String str){
		super(str);
		Poi = new ArrayList();
		setLayout(null);
		setVisible(true);
		setBounds(300,300,400,400);
		setBackground(Color.BLUE);
		this.addMouseListener(new Monitor());
		/********直接点击查号关闭窗口/
		this.addWindowListener(new Monitorwin());
		/********/
	}
	public void paint(Graphics g){
		Iterator it = Poi.iterator();
		while(it.hasNext()){
			Point p =(Point) it.next();
			g.setColor(Color.red);
			g.fillOval(p.x, p.y, 10, 10);
		}
	}
	public void addPoint(Point p){
		Poi.add(p);
	}
	public class Monitor extends MouseAdapter{
		public void mousePressed(MouseEvent e){
			MouseFrame f = (MouseFrame)e.getSource();
			f.addPoint(new Point(e.getX(),e.getY()));
			f.repaint();
		}
	}
	/********/
	public class Monitorwin extends WindowAdapter{
		public void windowClosing(WindowEvent e){
			setVisible(true);
			System.exit(0);
		}
	}
	/********/
	
}


package awt;
import java.awt.*;
import java.awt.event.*;
public class Mouse {
	public static void main(String[] args){
		new MouseFrame("Clicking..");
	}
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值