Posted on Leave a comment solution

Mouse events with java.
[code lang=”java”]/*
* draw lines in canvas
* ralph @today

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

Your email address will not be published. Required fields are marked *

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