ara asa

ara asa

  • NA
  • 1
  • 1.3k

Java programming

Nov 20 2011 7:52 PM

I am beginner to java programming can any one solve this problem for me?

I have a class for drawing a line and after that i need to have a picture class that contains array of objects that i use to crate a line and add it to that array, every time I call a method called addLine
that line values should be added to that array object that I defined before; i done some thing but when i try to test the array to know if it contains the line values or not it just returns I don't know it is some thing like reference
the following is my code :
public class Line {

// Instance variables
private int x1,x2;
private int y1,y2;



// constructor with input values
public Line( int x1, int y1, int x2, int y2 )
{
this.x1 = x1; // set x1 coordinate of first endpoint
this.y1 = y1; // set y1 coordinate of first endpoint
this.x2 = x2; // set x2 coordinate of second endpoint
this.y2 = y2; // set y2 coordinate of second endpoint

} // end Line constructor

// Draw the line
public void draw( EasyGraphics g )
{

g.drawLine( x1, y1, x2, y2 );

}

}

this is the picture class which i wrote to contain arrays:
public class Picture{

private int width,height;
int length = 50;

EasyGraphics window;

//define array of objects
Line[] arrayLine;
//define constructor
public Picture(int width,int height)
{
this.width = width;
this.height = height;

window = new EasyGraphics( width, height);

//initializing arrays
arrayLine = new Line[length];
}

public void addLine(int x1,int y1,int x2,int y2)
{


for(int i=0;i<length-1;i++)
{
arrayLine[i] = new Line( x1, y1, x2, y2);

}
arrayLine[0].draw(window);
System.out.print(arrayLine[0]);
}
public static void main(String args[])
{
Picture picture = new Picture(500,300);
picture.addLine(10,10,100,100);
}


}

Answers (1)