【发布时间】:2017-03-12 18:09:32
【问题描述】:
我对 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 什么意思?
-
您在哪里显示您的图块/GridLayout?无论如何,我建议使用 JPanel 并在其上绘图,因为我认为它会容易得多...
-
你的 FloorPlan 课程在哪里?