1
我對Java很新,但我嘗試使用數組創建一個房間的地圖,但是我不知道如何將其添加到我的應用程序類。由於代碼太長,我將分享我一直在嘗試使用的視圖類,以便將其添加到我的應用程序中。我刪除了添加其他組件到我的應用程序的代碼,因爲它的長度,但附加的圖片是我得到的輸出。向Java應用程序添加地圖陣列
任何幫助,將不勝感激。我已經用盡了所有的選擇。謝謝。
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
public class FloorBuilderView extends GridPane {
private FloorPlan model;
//component on window
private Button buildingOverview;
private Button roomTilesColor;
private FloorPlan fp;
private Button[][] buttons;
private RadioButton exit;
private RadioButton walls;
private RadioButton roomTiles;
private RadioButton selectRoom;
private TextField floorSummary;
private Label selectEdit;
private Label floorLayoutLabel;
private Label floorSummaryLabel;
public FloorBuilderView(){
// model = fp; // Store the model so that the update() method can access it
fp = FloorPlan.floor1();
fp = new FloorPlan(20, "Main Floor");
int[][] tiles = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,1,1},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
for (int r=0; r<20; r++)
for (int c=0; c<20; c++)
fp.setWallAt(r,c,tiles[r][c]==1);
setPadding(new Insets(10,10,10,10));
//floorPlan = new Panel(new GridLayout(fp.size(), fp.size(), 0, 0));
//buttons = new Button[fp.size()][fp.size()];
update();
}
public void update() {
}
}
你在哪裏顯示它? – user7185318
@ user7185318你是什麼意思? – comp1005
你在哪裏顯示你的瓷磚/ GridLayout?無論如何,我建議使用JPanel並繪製它,因爲我認爲它會容易得多... – user7185318