package com.graphic3;

import java.awt.*;
import java.awt.event.*;

public class GraphicsEx3 extends Frame implements MouseMotionListener{
	int x=0;
	int y=0;

	public static void main(String[] args) {
		new GraphicsEx3("GraphicsEx3");
	}

	public GraphicsEx3(String title){
		super(title);
		addMouseMotionListener(this);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent we){
				System.exit(0);
			}

		});
		
		//Frame   X   Y   width height
		setBounds(100,100,500,500);
		setVisible(true);
	}
	public void paint(Graphics g){
		g.drawString("마우스를 드래그 해보세요", 10, 50);
		g.drawString("*", x, y);
	}
	
	public void update(Graphics g){
		paint(g);
	}
	
	public void mouseMoved(MouseEvent me){}
	
	public void mouseDragged(MouseEvent me){
		x = me.getX();
		y = me.getY();
		/*update(Graphics g)를 재정의 하지 않음
		paint(Graphics g)호출
		update(Graphics g)를 재정의 하면 update 메소드 호출*/
		repaint();
	}

}


'Java > AWT' 카테고리의 다른 글

예비  (0) 2012.04.13
Graphic paint 사용법  (0) 2012.04.13
Graphic 이미지 넣기  (0) 2012.04.13
Graphic 도형 그리기  (0) 2012.04.13
Graphic Color  (0) 2012.04.13

+ Recent posts