Access to an object via a LinkedList
in
Programming Questions
•
11 months ago
Hi,
I am currently facing a problem with LinkedList and more specially get an attribute from an object
This is the declaration of the class AMORCE which is define in the variable.pde file :
- public class AMORCE{
- public float [][] tableauDePoint;
- public int nombrePoint;
- public int choixTransformation;
- public public UNPOINT centreTransformation;
- public AMORCE(){
- this.choixTransformation = 0;
- this.nombrePoint = nombrePointBase;
- this.centreTransformation.x=0;
- this.centreTransformation.y=0;
- }
- public UNPOINT getCenter(){
- return centreTransformation;
- }
- }
- public LinkedList lesAmorces;
- public class UNPOINT{
- public int x;
- public int y;
- public boolean arrete = false;
- }
This is the instanciation of the LinkedList in the void setup:
- lesAmorces= new LinkedList();
- lesAmorces.add(new AMORCE());
So I create a
LinkedList
lesAmorces which contained an object
AMORCE....
And finally this is the line with the error in the draw function:
- lesAmorces.getLast().getCenter().x = xCen; //getLast return the last object of the LinkedList
- lesAmorces.getLast().centreTransformation.y = yCen;
To sum up, I want to get and set the x and y coordinates of the object
AMORCE which is contained in the LinkedList
lesAmorces.
How to do this and why I get the error "The function getcenter() does not exist"?
I try to cast my variables like this:
- temp = lesAmorces.getLast();
- ((AMORCE)temp).setCenter((int)xCen, (int)yCen);
... but it doesn't work and I get the error: "cannot converted from object to UNPOINT?
Thank in advance for your answers :-)
1