2017-05-18 1 views
-2

나는 숙제를 풀고 싶다. 시작하는 법을 모른다. 목표는 GUI 양식JavaFX으로 변경하는 것입니다. 첫 번째는 Button1을 포함하는 홈 형식이며 사용자가 Button1을 클릭하면 두 번째 양식을 표시하고 첫 번째를 닫습니다.버튼을 클릭하면 다른 윈도우 표시 JavaFX

어떻게 수행하나요? 나에게 예제를 줄 수 있기를 바랍니다.

읽고 도와 주셔서 감사합니다.

+0

그래, 난 그 유래가 해결사 –

+0

이 좋아 내가 나에게 –

답변

-1

당신은 이런 일을 할 수 있지만,이 예제의 아이디어를 살펴 후에도 자신의 일을하려고 우리가 연습과 훈련을 통해 학습을 명심하시기 바랍니다 수 있습니다

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

public class TwoForms extends Application { 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     StackPane root = new StackPane(); // TLC (Top Layer Container) a root container for all other components, which in your case is the Button 
     Button button = new Button("Go To Second Form"); // the button 
     root.getChildren().add(button); // add the button to the root 
     Scene scene = new Scene(root, 500,500); // create the scene and set the root, width and height 
     primaryStage.setScene(scene); // set the scene 
     primaryStage.setTitle("First Form"); 
     primaryStage.show(); 

     // add action listener, I will use the lambda style (which is data and code at the same time, read more about it in Oracle documentation) 
     button.setOnAction(e->{ 
      //primaryStage.close(); // you can close the first stage from the beginning 

      // create the structure again for the second GUI 
      // Note that you CAN use the previous root and scene and just create a new Stage 
      //(of course you need to remove the button first from the root like this, root.getChildren().remove(0); at index 0) 
      StackPane root2 = new StackPane(); 
      Label label = new Label("Your are now in the second form"); 
      root2.getChildren().add(label); 
      Scene secondScene = new Scene(root2, 500,500); 
      Stage secondStage = new Stage(); 
      secondStage.setScene(secondScene); // set the scene 
      secondStage.setTitle("Second Form"); 
      secondStage.show(); 
      primaryStage.close(); // close the first stage (Window) 
     }); 
    } 

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

    } 

} 

결과 버튼을 클릭 한 후 enter image description here

-> 두 번째 창.

enter image description here

+0

감사하기 위해 다른 사람을 기다리는 U 감사합니다, 그 일이 지금 내가 그것을 developp합니다 :) –

+0

확인 메신저 U없이 문제를 이해 숙제 아니라는 것을 알고 –

관련 문제