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:

problem in drawing line

Posted by Theesan on July 07, 2001 at 10:42 AM

I have a problem in drawng graphis.Here I gave a program to draw some lines .But the program only draws the last line.
In C or other languages we can all a funtion directly to draw lines from any loop. But it is not possible in java.I know that
storing all lines in an array we can draw all lines. But I want to know how to draw the lines directly from the loop without
an array.If you know the answer please let it me to know.
Thanx
Here is the program.
import java.awt.*;
public class Test extends Canvas {
Frame F = new Frame();
int x1,x2,y1,y2;
public Test() {
F.setSize(300,300);
F.setVisible(true);
setSize(200,200);
setVisible(true);
F.add(this);
}
public void aa() {
x1=0;
x2=100;
for (int i=0;i<100;i=i+100) {
y1=i;
y2=i;
repaint();
}
}
public void paint(Graphics g) {
g.drawLine(x1,y1,x2,y2);
}
public void update(Graphics g) {
paint(g);
}
public static void main (String[] args) {
Test t= new Test();
t.aa();
}
}





Replies:

Sponsored Links



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