Skip to content

Instantly share code, notes, and snippets.

@sedj601
Created February 24, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sedj601/57457982e65fe6904b616c921e25b50a to your computer and use it in GitHub Desktop.
Save sedj601/57457982e65fe6904b616c921e25b50a to your computer and use it in GitHub Desktop.
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class SceneOne
{
private final Scene scene1;
private final Stage primaryStage;
private final Button button1 = new Button("Go to scene 2");
private final Label label1 = new Label("This is the first scene");
public SceneOne(Stage primaryStage)
{
VBox layout1 = new VBox(20);
layout1.getChildren().addAll(label1, button1);
scene1 = new Scene(layout1, 300, 250);
this.primaryStage = primaryStage;
}
public Scene getScene1()
{
return scene1;
}
public void setSceneToSwitchTo(Scene scene)
{
button1.setOnAction(e -> this.primaryStage.setScene(scene));
}
}
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class SceneTwo
{
private final Scene scene2;
private final Stage primaryStage;
Label label2 = new Label("This is the second scene");
Button button2 = new Button("Go to scene 1");
public SceneTwo(Stage primaryStage)
{
VBox layout2 = new VBox(20);
layout2.getChildren().addAll(label2, button2);
scene2 = new Scene(layout2, 300, 250);
this.primaryStage = primaryStage;
}
public Scene getScene2()
{
return scene2;
}
public void setSceneToSwitchTo(Scene scene)
{
button2.setOnAction(e -> this.primaryStage.setScene(scene));
}
}
import javafx.application.Application;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class TestingGroundsTwo extends Application
{
@Override
public void start(Stage primaryStage)
{
SceneOne sceneOne = new SceneOne(primaryStage);
SceneTwo sceneTwo = new SceneTwo(primaryStage);
sceneOne.setSceneToSwitchTo(sceneTwo.getScene2());
sceneTwo.setSceneToSwitchTo(sceneOne.getScene1());
primaryStage.setTitle("Hello World!");
primaryStage.setScene(sceneOne.getScene1());
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment