BasicMouseDragger

Retired DISLab
이동: 둘러보기, 찾기
import acm.program.*;
import acm.graphics.*;
 
import java.awt.event.*;
 
public class BasicMouseDragger extends GraphicsProgram {
 
	private GOval theCircle;
	private boolean draggingCircle = false;
 
	public void run() {
 
		theCircle = new GOval(150, 150);
		add(theCircle, 100, 100);
 
		addMouseListeners();
	}
 
	public void mousePressed(MouseEvent e) {
		if (getElementAt(e.getX(), e.getY()) == theCircle) {
			draggingCircle = true;
		}
	}
 
	public void mouseReleased(MouseEvent e) {
		draggingCircle = false;
	}
 
	public void mouseDragged(MouseEvent e) {
		if (draggingCircle) {
			theCircle.setLocation(e.getX(), e.getY());
		}
	}
 
	public static void main(String[] args) {
		String[] newArgs = new String[args.length + 1];
		System.arraycopy(args, 0, newArgs, 0, args.length);
		newArgs[args.length] = "code=" + new SecurityManager(){
			public String className() {
				return this.getClassContext()[1].getCanonicalName();
			}
		}.className();
		GraphicsProgram.main(newArgs);
	}
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기