Java

넷빈즈에서 씬빌더 화면전환 ....

1
public void changeSceneButtonCliked(ActionEvent event) throws IOException { Parent m_Main_view_parent = FXMLLoader.load(getClass().getResource("m_Main_view.fxml")); Scene m_Main_view_scene = n..
 public void changeSceneButtonCliked(ActionEvent event) throws IOException
    {
        Parent m_Main_view_parent = FXMLLoader.load(getClass().getResource("m_Main_view.fxml"));
        Scene m_Main_view_scene = new Scene(m_Main_view_parent);
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(m_Main_view_scene);
        window.show(); 
    }

/* --------------------1 --------------------------*/ 

   public void changeSceneButtonCliked(ActionEvent event) throws IOException
    {
        Parent m_Movie_info_regis_parent = FXMLLoader.load(getClass().getResource("m_Main_info_regis.fxml"));
        Scene m_Movie_info_regis_scene = new Scene(m_Movie_info_regis_parent);
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(m_Movie_info_regis_scene);
        window.show(); 
    }

1번으로 적용하니 화면전환이 됐는데 그대로 가져다가 getResource 값만 변환 하려는 창으로 바꿨는데 

이렇게 하니 적용이 안되네요... 

어떤걸 또 변경해야하나요..? 

초보코린이 님께서 2022-05-28에 Java에 올린 질문

댓글

1개의 답변

1
아래는 씬을 변환하는 코드입니다. 참고가 되시기 바랍니다.   Main.java package application; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.stage.Stage; import javafx...

아래는 씬을 변환하는 코드입니다. 참고가 되시기 바랍니다.

 

Main.java

package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;

public class Main extends Application {

  @Override
  public void start(Stage stage) {
    try {

      Parent root = FXMLLoader.load(getClass().getResource("Scene1.fxml"));
      Scene scene = new Scene(root);
      stage.setScene(scene);
      stage.show();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    launch(args);
  }
}

 

SceneController.java

package application;

import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class SceneController {

  private Stage stage;
  private Scene scene;
  private Parent root;

  public void switchToScene1(ActionEvent event) throws IOException {
    root = FXMLLoader.load(getClass().getResource("Scene1.fxml"));
    stage = (Stage)((Node) event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }

  public void switchToScene2(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("Scene2.fxml"));
    stage = (Stage)((Node) event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }
}

 

 

무린 2022-06-11
사탕 주기
무린 님께서 2022-06-11에 Java에 올린 글
보관하기

댓글

조회수 692
답글 1
URL