日期:2014-05-18 浏览次数:20848 次
package event;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
public class MouseEventTest extends Frame{
/**
*
*/
private static final long serialVersionUID = -2790306218418130626L;
public void paint(Graphics g)
{
super.paint(g);
final Graphics2D g2 = (Graphics2D)g;
BasicStroke pen = new BasicStroke(3.0f);
g2.setStroke(pen);
g2.setColor(Color.BLUE);
this.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
System.out.println(e.getButton());
Ellipse2D.Float circle = new Ellipse2D.Float(140,140,15,15);
g2.draw(circle);
}
});
}
MouseEventTest()
{
this.setSize(400, 300);
this.setVisible(true);
this.setLocation(300, 300);
this.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
// System.out.println(e.getButton()+"Click");
// paint(e.ge );
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
});
}
public static void main(String[] args)
{
new MouseEventTest();
}
}