我试图调用一个方法,我将其放在另一个类中只是为了改善程序的结构,此方法将删除一个节点(行),然后再调用另一个计算坐标的方法以及是否可以删除该坐标线。因此,我几乎尝试了所有事情,包括接口,导入类,使用静态方法...等等。我现在创建类的实例,然后调用方法“ delWalls”,但是每当我得到此“应用程序异常”构造函数”,我将在下面保留完整的打印内容。
方法'delWalls'在类'DeleteWall'中,它调用'delNode'的方法在Main类中,由于我继承了main类,因此仍然可以访问。
//problem
DeleteWall ok = new DeleteWall();
public void demo(){
ok.delWalls(30,0,30,30);
//method in class 'DeleteWall' which i'm calling
public class DeleteWall {
Main werk = new Main();
public void delWalls(int Sx, int Sy, int Ex, int Ey) {
werk.delNode(Sx, Sy, Ex, Ey);
}
} // Main类的del节点方法部分
public void delNode(int Sx, int Sy, int Ex, int Ey) {
//System.out.println("run me");
ObservableList<Node> nodes = pane.getChildren();
sizeN = nodes.size();
//System.out.println(sizeN);
List<List<Integer>> cells = new ArrayList<>();
int j = 0;
for (int i = 0; i < sizeN; i++) {
//check if size of list is greater than 0 is to esnure no out of bounds error
Node val = nodes.get(i);
List<Integer> preCells = new ArrayList<>();
double valx = (val.getLayoutBounds().getMinX() + 0.5);
double valy = (val.getLayoutBounds().getMinY() + 0.5);
double endx = (val.getLayoutBounds().getMaxX() - 0.5);
double endy = (val.getLayoutBounds().getMaxY() - 0.5);
//System.out.println("cell (" + valx + ',' + valy + ')');
preCells.add((int) valx);
preCells.add((int) valy);
preCells.add((int) endx);
preCells.add((int) endy);
//System.out.println(preCells);
cells.add(preCells);
}
//System.out.println(cells);
boolean done = false;
while (!done) {
if (j > cells.size() - 1) break;
int xF = cells.get(j).get(0);
int yF = cells.get(j).get(1);
int eXf = cells.get(j).get(2);
int eYf = cells.get(j).get(3);
//System.out.println(cells);
if (Sx == xF && Sy == yF && Ex == eXf && Ey == eYf) {
pane.getChildren().remove(j);
//System.out.println(Sx);
//System.out.println("removed");
//break;
done = true;
j = 0;
//System.out.println("DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE DONE ");
}
j++;
}
}