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..");
}
}
java鼠标监听器画图+点击X关闭窗口
最新推荐文章于 2024-03-30 19:31:10 发布