The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Could you help me to draw line using mouse input

Posted by Theesan on February 10, 2001 at 12:37 AM

I tried draw line with mouse input.The program is shown below .It is compiled but at runtime it throws exeption.I could not identify the problem

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public abstract class Linel extends Appletimplements MouseListener{
int x1,x2,y1,y2;
public void init() {
addMouseListener(this);
}
public voidmousePressed(MouseEvent e) {
x1=e.getX();
y1=e.getY();
mouseReleased(e);
}
public voidmouseReleased(MouseEvent e) {
x2 =e.getX();
y2 =e.getY();
repaint();
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void paint (Graphics g){
g.drawLine(x1,y1,x2,y2);
}
}
Thank you



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us