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:

Rg: Line To Java

Posted by Sriram on February 14, 2001 at 5:24 AM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Line1 extends Applet implements MouseListener{
int x1,x2,y1,y2;
public void init() {
addMouseListener(this);
}
public void mousePressed(MouseEvent e) {
x1=e.getX();
y1=e.getY();
mouseReleased(e);
}
public void mouseReleased(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);
}
}

The above code should do your work. the problem with your's is remove abstract in the class header.



Replies:

Sponsored Links



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