DragUsingGObjectEvent

Retired DISLab
Swpark (토론 | 기여) 사용자의 2014년 1월 26일 (일) 09:50 버전
(비교) ← 이전 판 | 현재 판 (비교) | 다음 판 → (비교)
이동: 둘러보기, 찾기
import acm.program.*;
import acm.graphics.*;
import java.awt.*;
import java.awt.event.*;
 
public class DragUsingGObjectEvent extends GraphicsProgram {
 
	public void init() {
		GRect rect = new GRect(100, 100, 150, 100);
		rect.setFilled(true);
		rect.setColor(Color.RED);
		rect.addMouseListener(this);
		rect.addMouseMotionListener(this);
		add(rect);
 
		GOval oval = new GOval(300, 115, 100, 70);
		oval.setFilled(true);
		oval.setColor(Color.GREEN);
		oval.addMouseListener(this);
		oval.addMouseMotionListener(this);
		add(oval);
	}
 
	public void mousePressed(MouseEvent e) {
		last = new GPoint(e.getPoint());
	}
 
	public void mouseDragged(MouseEvent e) {
		GObject gobj = (GObject) e.getSource();
		gobj.move(e.getX() - last.getX(), e.getY() - last.getY());
		last = new GPoint(e.getPoint());
	}
 
	public void mouseClicked(MouseEvent e) {
		GObject gobj = (GObject) e.getSource();
		gobj.sendToFront();
	}
 
	/* Private instance variables*/
	private GPoint last;
 
	private static final long serialVersionUID = 1;
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기