我有這樣的代碼,它使用一個開源的API(Sweethome3D)。我想要做的是檢查房間是平行四邊形還是方形,然後調用方法並更改牆壁和房間的值。但如果我嘗試這樣做,它會給我錯誤。你有什麼想法我可以做到這一點?的Java:調用的方法中的方法,並使用相同的變量
@Override
public Home createHome() {
Home home = super.createHome();
if (Shape_of_Room.equals("Parallelogram")) {
float[][] points = { { 0f, 0f }, { 0f, 400f }, { 625f, 400f },
{ 625f, 400f }, { 625f, 0f }, { 0f, 0f } };
Room Parallelogram_Room = new Room(points);
Parallelogram_Room.setAreaVisible(true);
// Add new Room to Home
home.addRoom(Parallelogram_Room);
// Check for Ceiling and Floor Display
if (Floor_Display.equals("true")) {
Parallelogram_Room.setFloorVisible(true);
}
else if (Floor_Display.equals("false")) {
Parallelogram_Room.setFloorVisible(false);
}
if (Ceiling_Display.equals("true")) {
Parallelogram_Room.setCeilingVisible(true);
}
else if (Ceiling_Display.equals("false")) {
Parallelogram_Room.setCeilingVisible(false);
}
Wall Left_Wall = new Wall(0, 0, 0, 400, (float) 7.62);
Wall North_Wall = new Wall(0, 400, 625, 400, (float) 7.62);
Wall Right_Wall = new Wall(625, 400, 625, 0, (float) 7.62);
Wall South_Wall = new Wall(625, 0, 0, 0, (float) 7.62);
Left_Wall.setWallAtEnd(North_Wall);
North_Wall.setWallAtEnd(Right_Wall);
Right_Wall.setWallAtEnd(South_Wall);
South_Wall.setWallAtEnd(Left_Wall);
// Check the color of the Walls
// Values set from site
// http://cloford.com/resources/colours/500col.htm
// and by the calculator
// http://www.shodor.org/stella2java/rgbint.html
int k;
String[] Color = { "Grey", "Red", "Green", "Blue", "Yellow",
"White" };
int[] Color_Number = { 13882323, 16764108, 7456369, 13421823,
11394815, 16777215 };
for (k = 0; k < 6; k++) {
if (Left_Wall_Color.equals(Color[k])) {
Left_Wall.setLeftSideColor(Color_Number[k]);
}
if (North_Wall_Color.equals(Color[k])) {
North_Wall.setLeftSideColor(Color_Number[k]);
}
if (Right_Wall_Color.equals(Color[k])) {
Right_Wall.setLeftSideColor(Color_Number[k]);
}
if (South_Wall_Color.equals(Color[k])) {
South_Wall.setLeftSideColor(Color_Number[k]);
}
}
// Check if the walls are Matt or Shiny
if (Shiny_Matt.equals("Matt")) {
Left_Wall.setLeftSideShininess(0);
North_Wall.setLeftSideShininess(0);
Right_Wall.setLeftSideShininess(0);
South_Wall.setLeftSideShininess(0);
}
else if (Shiny_Matt.equals("Shiny")) {
Left_Wall.setLeftSideShininess(1);
North_Wall.setLeftSideShininess(1);
Right_Wall.setLeftSideShininess(1);
South_Wall.setLeftSideShininess(1);
}
home.addWall(Left_Wall);
home.addWall(North_Wall);
home.addWall(Right_Wall);
home.addWall(South_Wall);
}
// Modify home as you wish here
System.out.println("method called");
return home;
}
有什麼錯誤兄弟? – Shawn
錯誤在於eclipse不能識別當我嘗試在另一種方法中使用它時創建的房間和家庭的對象(或者即使我在If語句之外使用它們) – Mitsaki
您也可以發佈代碼那不工作(主要??)?方法代碼不足以讓我們幫助您。 –