Results 1 to 6 of 6
  1. #1
    pmyers0316 is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default JavaFX Program - Problem with Scenes

    I have an equations program that I'm working on, which randomly selects one of 50 equations, then takes the user through a series of scenes in order to solve it. Once the user solves the equation, they're asked if they want another equation. If they answer no, the program closes. If they answer yes, the program is supposed to randomly select another equation, then take them through the scenes to solve that one.

    The program works just as I want it to the first time through. However, if the user selects "yes" for another equation, the program displays the END of the first scene, showing them the previous problem that they've already solved.

    How can I send the user to the beginning of the scene, so that a new equation is selected?

    Hereís the relevant code for Scene 1:

    Java FX Code:
    package Equations;
    
    import java.util.Random;
    import javafx.application.*;
    import javafx.stage.*;
    import javafx.scene.*;
    import javafx.scene.layout.*;
    import javafx.scene.text.Text;
    import javafx.scene.control.*;
    import javafx.event.*;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    
    public class equationsapp extends Application
    	implements EventHandler<ActionEvent> {
    
    	public static void main(String[] args) {
    		launch(args);
    	}
    
    	@Override public void start(Stage primaryStage) {
    		
    		stage = primaryStage;
    		
    		Random eqrdmzr = new Random();
    		int randomNumber = eqrdmzr.nextInt(3) + 1;
    
    			if (randomNumber == 1) {
    				isolCounterCoeff = 2;
    				isolVrblb = new Label("+");
    				isolCounter1a = 7;
    				isolCounter2a = 17;
    				slvCoeff = 2;
    				slvEqVrblTerm = new Text("2n");
    				slvEqWhlNmbrInt = 10;
    				slvEqWhlNmbr = new Text("10");
    			}
    
    			if(randomNumber == 2) {
    				isolCounterCoeff = 2;
    				isolVrblb = new Label("+");
    				isolVrblb.setVisible(false);
    				isolCounter1a = -18;
    				isolCounter2a = 4;
    				slvCoeff = 2;
    				slvEqVrblTerm = new Text("2n");
    				slvEqWhlNmbrInt = 22;
    				slvEqWhlNmbr = new Text("22");
    			}
    
    			if(randomNumber == 3) {
    				isolCounterCoeff = 3;
    				isolVrblb = new Label("+");
    				isolVrblb.setVisible(false);
    				isolCounter1a = -5;
    				isolCounter2a = 19;
    				slvCoeff = 3;
    				slvEqVrblTerm = new Text("3n");
    				slvEqWhlNmbrInt = 24;
    				slvEqWhlNmbr = new Text("24");
    			}
    			
    		//Build Scene 1 - Top BorderPane
    		Text isolText = new Text("Isolate the Variable Term");
    		isolText.setStyle("-fx-font-size: 16pt");
    
    		//Build Scene 1 - Center BorderPane
    		Label isolCoeff = new Label();
    		isolCoeff.setStyle("-fx-font-size: 24pt;");
    		isolCoeff.setText(Integer.toString(isolCounterCoeff));
    
    		Label isolVrbl = new Label("n");
    		isolVrbl.setStyle("-fx-font-size: 24pt;");
    
    		isolVrblb.setStyle("-fx-font-size: 24pt;");
    		isolVrblb.managedProperty().bind(isolVrblb.visibleProperty());
    
    		Label isolEqIntLeft = new Label();
    		isolEqIntLeft.setStyle("-fx-font-size: 24pt;");
    		isolEqIntLeft.setPadding(new Insets(0, 10, 0, 0));
    		isolEqIntLeft.setText(Integer.toString(isolCounter1a));
    		isolEqIntLeft.managedProperty().bind(isolEqIntLeft.visibleProperty());
    
    		Label isolEqualSign = new Label("=");
    		isolEqualSign.setStyle("-fx-font-size: 24pt;");
    
    		Label isolEqIntRight = new Label();
    		isolEqIntRight.setStyle("-fx-font-size: 24pt;");
    		isolEqIntRight.setPadding(new Insets(0, 0, 0, 10));
    		isolEqIntRight.setText(Integer.toString(isolCounter2a));
    
    		//Build Scene 1 - Bottom BorderPane
    		Label isolLbl1 = new Label();
    		isolLbl1.setStyle("-fx-font-size: 22pt;");
    
    		isolEqIntLeft.setText(Integer.toString(isolCounter1a));
    		isolLbl1.setText(Integer.toString(isolCounter1b));
    
    		//Create GridPanes and Fill Them
    		GridPane isolGridPane1 = new GridPane();
    		isolGridPane1.setAlignment(Pos.CENTER);
    		isolGridPane1.add(isolText, 0, 0);
    
    		GridPane isolGridPane2 = new GridPane();
    		isolGridPane2.setAlignment(Pos.CENTER);
    		isolGridPane2.add(isolCoeff, 0, 0);
    		isolGridPane2.add(isolVrbl, 1, 0);
    		isolGridPane2.add(isolVrblb, 2, 0);
    		isolGridPane2.add(isolEqIntLeft, 3, 0);
    		isolGridPane2.add(isolEqualSign, 4, 0);
    		isolGridPane2.add(isolEqIntRight, 5, 0);
    
    		GridPane isolGridPane3 = new GridPane();
    		isolGridPane3.setAlignment(Pos.CENTER);
    		isolGridPane3.setHgap(25.0);
    		isolGridPane3.setVgap(10.0);
    		isolGridPane3.setPadding(new Insets(0, 0, 20, 0));
    		isolGridPane3.add(isolbtn1, 0, 0); 
    		isolGridPane3.add(isolLbl1, 1, 0);
    		isolGridPane3.add(isolBtn2, 2, 0);
    		isolGridPane3.add(isolBtn3, 4, 0);
    		isolGridPane3.add(isolLbl2, 5, 0);
    		isolGridPane3.add(isolBtn4, 6, 0);
    		isolGridPane3.add(isolContinueBtn, 3, 1);
    
    		//Add GridPane to BorderPane
    		BorderPane isolBorderPane = new BorderPane();
    		isolBorderPane.setTop(isolGridPane1);
    		isolBorderPane.setCenter(isolGridPane2);
    		isolBorderPane.setBottom(isolGridPane3);
    
    		//Add BorderPane to Scene
    		scene1 = new Scene(isolBorderPane, 500, 300);
    
    		//Add the scene to the stage, set the title and show the stage
    		primaryStage.setScene(scene1);
    		primaryStage.setTitle("Equations");
    		primaryStage.show();
    Hereís the event handler thatís supposed to send them back to the start of Stage 1:

    Java FX Code:
    		Button yesBtn = new Button("Yes");
    		yesBtn.setStyle("-fx-font-size: 12pt;");
    		yesBtn.setOnAction(new EventHandler<ActionEvent>() {
    			public void handle (ActionEvent event) {
    				if (event.getSource() == yesBtn) {
    				stage.setScene(scene1);
    				}
    			}
    		});
    Last edited by pmyers0316; 05-29-2015 at 01:23 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: JavaFX Program - Problem with Scenes

    Moved from New to Java to JavaFX.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: JavaFX Program - Problem with Scenes

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    pmyers0316 is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default Re: JavaFX Program - Problem with Scenes

    I don't understand this comment. I'm trying to cast a wide net to get help with this problem. Is that wrong?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: JavaFX Program - Problem with Scenes

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    pmyers0316 is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default Re: JavaFX Program - Problem with Scenes

    I understand. Thank you.

Similar Threads

  1. Keep PrintStream Redirect across multiple scenes
    By tsgiannis in forum Advanced Java
    Replies: 0
    Last Post: 02-26-2015, 07:00 AM
  2. JavaFX Book | Learn JavaFX More In Depth
    By SnakeDoc in forum JavaFX
    Replies: 0
    Last Post: 05-17-2013, 11:10 PM
  3. Problem when resize graph JavaFX 2
    By susieferrari in forum JavaFX
    Replies: 13
    Last Post: 04-26-2012, 07:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •