package com.graphic3;//Graphic paint 사용법
import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseMotionListener;
public class GraphicsEx2 extends Frame implements MouseMotionListener{
int x= 0;
int y= 0;
public static void main(String[] args) {
new GraphicsEx2("GraphicsEx2");
}
public GraphicsEx2(String title){
super(title);
addMouseMotionListener(this);
//익명내부 클래스 형태의 이벤트 처리
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
//Frame
setBounds(100,100,500,500);
setVisible(true);
}
public void paint(Graphics g){
g.drawString("마우스를 움직여보세요.",10,50);
g.drawString("*",x,y);
}
public void mouseMoved(MouseEvent me){
x =me.getX();
y =me.getY();
repaint();//paint (graphic g)를 호출
//paint를 직접 호출할 수 없기때문에 repaint로 호출
}
public void mouseDragged(MouseEvent me){}
}//class