DrawLine

Retired DISLab
Swpark (토론 | 기여) 사용자의 2014년 1월 26일 (일) 09:50 버전
(비교) ← 이전 판 | 현재 판 (비교) | 다음 판 → (비교)
이동: 둘러보기, 찾기
/*
 * File: DrawLine.java
 * -------------------
 * This program allows users to create lines on the graphics
 * canvas by clicking and dragging with the mouse. The line
 * is redrawn from the original point to the new endpoint, which
 * makes it look as if it is connected with a rubber band.
 */
 
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
 
/** This class allows users to draw lines on the canvas */
public class DrawLine extends GraphicsProgram {
 
	/** Initializes the program by enabling the mouse listeners */
	public void init() {
		addMouseListeners();
	}
 
	/** Called on mouse press to create a new line */
	public void mousePressed(MouseEvent e) {
		line = new GLine(e.getX(), e.getY(), e.getX(), e.getY());
		add(line);
	}
 
	/** Called on moues drag to reset the endpoint */
	public void mouseDragged(MouseEvent e) {
		line.setEndPoint(e.getX(), e.getY());
	}
 
	/* Private instance variables */
	private GLine line;
 
	private static final long serialVersionUID = 1;
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기