The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 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:

Futher doubt on it

Posted by Theesan on July 14, 2001 at 1:50 AM

Hi Kishori;
Thank you for your answer. But I still doubt. For example
consider the code given bellow.

import java.awt.*;
import java.awt.event.*;
public class Line extends Frame implements MouseListener{
int x1=-1;int x2=-1;int y1=-1;int y2=-1;

public Line() {
setVisible(true);
setSize(200,200);
addMouseListener(this);
aa();
}
public void aa() {
x1=0;x2=100;
for(int i =0;i<100;i=i+10){
y1 =i;
y2 =i;
repaint();
}
}
public void mousePressed (MouseEvent e) {
x1=e.getX();
y1=e.getY();
}
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) {
System.out.println("paint");
g.drawLine(x1,y1,x2,y2);
}
public void update(Graphics g) {
System.out.println("update");
paint(g);


}
public static void main(String[] args) {
Line l = new Line();
}
}

This code will not draw all the line when repaint call from "for loop".
Only last line will remain.But when mouse metheds calling (ie giving the
points using mouse)the repaint all lines will be there. Why any line
is not erased here?
Thankyou
Theesan





Replies:

Sponsored Links



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