I'm working on this javaFX application that creates an object "StructureNode" and update it's data as you update the screen UI inputs and then I assign this object to "TrussMember" which holds two instances of "StructureNode" and finally the "StructureSolver" is used to retrieve the data in "StructureNode" that exist in every "TrussMember" and use it as indexes for matrices.
the problem is that all values are read successfully except these two integers private int x_index=1 , y_index=2; they always return the initial value no matter what is it zero or one or hundred this problem is driving me crazy hope you can help with it.
StructureNode class //the object encapsulates the data
public class StructureNode {
.
.
.
private int x_index=0 , y_index=0;
.
.
.
public int getX_index() {
//System.out.println("x_index = " + x_index);
return x_index;
}
public void setX_index(int nex_index) {
x_index = nex_index;
System.out.println("x_index changed to " + x_index);
}
public int getY_index() {
//System.out.println("y_index = " +y_index);
return y_index;
}
public void setY_index(int ney_index) {
y_index = ney_index;
System.out.println("y_index changed to " + y_index);
}
TrussModelBuider class //the class that adds the "StrutureNode" to "StructureMember" and adds these members to a bigger model called "Truss".
public class TrussModelBuider{
private boolean isBuilt = false;
private Truss structure;
public TrussModelBuider(Truss truss){
structure = truss;
}
@Deprecated
public void addNode(double X, double Y){
StructureNode n = new StructureNode();
n.setCoordinates(new Coordinates(X, Y));
structure.addJoint(n);
System.out.println("+pt["+X+", "+Y+"]");
}
public void addNode(StructureNode n){
structure.addJoint(n);
System.out.println("+pt["+n.getCoordinates().getX_COO()+", "+n.getCoordinates().getY_COO()+"]");
}
public void removeNode(double X, double Y){
structure.getJoints().remove(findNodeIndex(X,Y));
}
private int findNodeIndex(double X, double Y){
int index = 0;
for (int i = 0; i < structure.getJoints().size(); i++) {
if (structure.getJoints().get(i).getCoordinates().getX_COO()==X
&& structure.getJoints().get(i).getCoordinates().getY_COO()==Y) {
index = i;
break;
}
}
return index;
}
public void addMember(TrussMember member){
structure.addMember(member);
System.out.println("+mem "+member.getID()+": "+member.getStartJoint()+", "+member.getEndJoint());
}
public void removeMember(int ID){
structure.getMembers().remove(findMember(ID));
}
}
public class StructureSolver {
private Truss structure;
.
.
.
public StructureSolver(Truss truss){
structure = truss;
}
.
.
.
public void setStructure(Truss structure) {
this.structure = structure;
}
.
.
.
private void createStructureStiffnessMatrix(){
K = new StiffnessMatrix(structure.getJoints().size()*2);
assignIds();
for (TrussMember member: structure.getMembers()) {
int Nx = member.getNx();
int Ny = member.getNy();
int Fx = member.getFx();
int Fy = member.getFy();
double lambdaX = calculateLambdaX(member);
double lambdaY = calculateLambdaY(member);
double lambdaXSq = lambdaX*lambdaX/ member.getLength();
double lambdaYSq = lambdaY*lambdaY/ member.getLength();
double lambdaXY = lambdaX*lambdaY/ member.getLength();
TrussMember class
public class TrussMember {
private StructureNode startJoint, endJoint;
.
.
.
public TrussMember() {
}
public TrussMember(StructureNode startJoint, StructureNode endJoint) {
this.startJoint = startJoint;
this.endJoint = endJoint;
}
.
.
. .
.
.
public double getLength() {
double calculatedLength = 0;
Point2D p1 = new Point2D(startJoint.getCoordinates().getX_COO(),
startJoint.getCoordinates().getY_COO());
Point2D p2 = new Point2D(endJoint.getCoordinates().getX_COO(),
endJoint.getCoordinates().getY_COO());
calculatedLength = p1.distance(p2);
return calculatedLength;
}
public StructureNode getStartJoint() {
return startJoint;
}
public void setStartJoint(StructureNode startJoint) {
this.startJoint = startJoint;
}
public StructureNode getEndJoint() {
return endJoint;
}
public int getNx(){return getStartJoint().getX_index();}
public int getNy(){return getStartJoint().getY_index();}
public int getFx(){return getEndJoint().getX_index();}
public int getFy(){return getEndJoint().getY_index();}
}
in the controller class #onActionMethod
StructureSolver solver = new StructureSolver();
solver.setStructure(truss);
solver.solve();
I tried using another thread and tried making them final with no initial value but always the same result.