0
기본적으로 제목이 말합니다. MenuBar와 Text처럼 childSet/map/table에 표시되지 않았다는 것을 알았습니다. 나는 무엇을 잘못 할 수 있 었는가? 어떤 이유로 더 자세한 정보를 추가해야합니까?Children/list/backingList에도 불구하고 JavaFx Canvas가 GridPane에 표시되지 않습니다.
내가하려는 것은 gridPane을 테스트로 표시하는 파란색 사각형을 가져 와서 캔버스에서 그리기를 시작할 수 있습니다. 당신이 Canvas
80 x 80
등의 크기를 지정하기 때문에
private GridPane hackingPane;
private int[] redData;
private int[] tilesetHeaderAddresses;
private TilesetHeader[] tilesetHeaders;
private int[] mapHeaderPointers;
private int[] mapHeaderBanks;
private int[] mapHeaderAddresses;
private MapHeader[] mapHeaders;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage hackingStage) {
initStage(hackingStage);
hackingStage.show();
}
private void initStage(Stage hackingStage) {
hackingPane = new GridPane();
Scene hackingScene = new Scene(hackingPane);
hackingStage.initStyle(StageStyle.DECORATED);
hackingStage.setScene(hackingScene);
hackingStage.setTitle("Red Hacker :)");
initGridPane(hackingStage);
}
private void initGridPane(Stage hackingStage) {
MenuBar hackingMB = new MenuBar();
final Menu fileMenu = new Menu("File");
MenuItem openMI = new MenuItem("Open");
Text hex = new Text("Tilesets");
Canvas tilesetCanvas = new Canvas(80, 80);
GraphicsContext gc = tilesetCanvas.getGraphicsContext2D();
fileMenu.getItems().add(openMI);
hackingMB.getMenus().add(fileMenu);
hackingPane.add(hackingMB, 0, 0, 1, 1);
GridPane.setHgrow(hackingMB, Priority.ALWAYS);
hackingPane.add(hex, 0, 1, 1, 1);
hex.setFont(new Font(25));
hex.setTextAlignment(TextAlignment.CENTER);
GridPane.setHalignment(hex, HPos.CENTER);
GridPane.setHgrow(hex, Priority.ALWAYS);
gc.setFill(Color.BLUE);
gc.fillRect(80,80,80,80);
hackingPane.add(tilesetCanvas, 0, 2, 1, 1);
GridPane.setMargin(tilesetCanvas, new Insets(0, 25, 25, 25));
openMI.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
openMIEvent(hackingStage);
}
});
}
private void openMIEvent(Stage hackingStage) {
FileChooser fc = new FileChooser();
fc.setTitle("Open File:");
File sf = fc.showOpenDialog(hackingStage);
if(sf != null){
try {
parseFile(sf);
} catch (IOException e) {
System.out.println("Error opening file");
}
}
}
private void parseFile(File sf) throws IOException {
FileInputStream in = null;
int i = 0;
int size;
redData = new int[(Math.toIntExact(sf.length()))];
size = redData.length;
try{
in = new FileInputStream(sf);
while(i < size){
redData[i] = in.read();
i++;
}
} finally{
if(in != null){
in.close();
}
}
getTilesetHeaderAddresses();
generateTilesetHeaders();
getMapHeaderPointers();
getMapHeaderBanks();
getMapHeaderAddresses();
generateMapHeaders();
System.out.println(":)");
}
private void getTilesetHeaderAddresses() {
int i = 0;
tilesetHeaderAddresses = new int[23];
while(i < 23){
tilesetHeaderAddresses[i] = (51134 + (i * 12));
i++;
}
}
private void generateTilesetHeaders() {
int i = 0;
tilesetHeaders = new TilesetHeader[23];
while(i < 23){
tilesetHeaders[i] = new TilesetHeader(redData, tilesetHeaderAddresses[i]);
i++;
}
}
private void getMapHeaderPointers() {
int i = 0;
mapHeaderPointers = new int[248];
while(i < 248){
short test1 = (short) (redData[(2*i)+431] << 8);
short test2 = (short) (redData[(2*i)+430] & 0xFF);
mapHeaderPointers[i] = (short) ((test1) | (test2));
i++;
}
}
private void getMapHeaderBanks() {
int i = 0;
mapHeaderBanks = new int[248];
while(i < 248){
mapHeaderBanks[i] = redData[49725+i];
i++;
}
}
private void getMapHeaderAddresses() {
int i = 0;
mapHeaderAddresses = new int[248];
while(i < 248){
mapHeaderAddresses[i] = (mapHeaderBanks[i]*0x4000) + (mapHeaderPointers[i]%0x4000);
i++;
}
}
private void generateMapHeaders() {
int i = 0;
mapHeaders = new MapHeader[248];
while((i < 248)){
if((i != 11) & (i != 105) & (i != 106) & (i != 107) & (i != 109) & (i != 110) & (i != 111) & (i != 112) & (i != 114) & (i != 115) & (i != 116) & (i != 117) & (i != 204) & (i != 205) & (i != 206) & (i != 231) & (i != 237) & (i != 238) & (i != 241) & (i != 242) & (i != 243) & (i != 244)){
mapHeaders[i] = new MapHeader(redData, mapHeaderAddresses[i], mapHeaderBanks);
}
i++;
}
}
}
와우. 나는 그것을 잡았어야했다. 감사 –