Drawline.java solution

Mouse events with java.

 * DrawLines.java
 * 		draw lines in canvas
 * ralph @today

import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;

public class Drawlines extends GraphicsProgram {

	public void run(){
		/* Tell Java that we're ready for the mouse */
	public void mousePressed(MouseEvent e){
		// start the line with a mousepressed event
		line = new GLine(e.getX(),e.getY(),e.getX(),e.getY());
	public void mouseDragged(MouseEvent e){
		/* end the line where we click */
		line.setEndPoint(e.getX(), e.getY());
	/* private instance variables */
	private GLine line;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.