1

I'm a really new programmer so idk if this question sounds really stupid but..

This is my main:

package culminating;

import javafx.application.Application;

& all other necessary imports...

public class CulminatingMAIN extends Application {

//Set Global variables
int count = 0;
String name;
String gender = "Boy";
Label testLabel = new Label(gender + " has been selected");


@Override
public void start(Stage primaryStage) throws Exception {

    /**
     * ************************ SCENE 1 WORK *************************
     */
    TextField nameTextField = new TextField();
    nameTextField.setMaxWidth(100);

    Label nameLabel = new Label("Please enter your name.");

    Label genderLabel = new Label();

    Label titleLabel = new Label("Math Adventure!");
    titleLabel.setFont(Font.font("Arial", FontWeight.BOLD, 30));

    Rectangle titleRectangle = new Rectangle();
    titleRectangle.setFill(Color.TOMATO);
    titleRectangle.setWidth(280);
    titleRectangle.setHeight(60);
    titleRectangle.setStroke(Color.BLACK);
    titleRectangle.setStrokeWidth(2.0);

    StackPane root = new StackPane(titleRectangle, titleLabel);

    //Set VBox properties
    VBox vbox1 = new VBox(25);
    vbox1.setAlignment(Pos.TOP_CENTER);
    vbox1.setPadding(new Insets(60, 0, 0, 0));
    vbox1.setStyle("-fx-background-color: lightskyblue");

    HBox genderBtnBox = new HBox(25);
    genderBtnBox.setAlignment(Pos.CENTER);

    //Set Scene 1 buttons
    Button enterNameBtn = new Button("Enter");
    Button goToScene2Btn = new Button("Continue");

    //Set Radio Button functionality here
    final ToggleGroup genderGroup = new ToggleGroup();

    RadioButton rb1 = new RadioButton("Boy");
    rb1.setToggleGroup(genderGroup);
    rb1.setUserData("Boy");
    rb1.setSelected(true);

    RadioButton rb2 = new RadioButton("Girl");
    rb2.setToggleGroup(genderGroup);
    rb2.setUserData("Girl");

    //Add panes, labels and buttons to the VBox
    vbox1.getChildren().addAll(root, nameLabel, nameTextField, enterNameBtn, genderLabel, genderBtnBox);

    Scene scene = new Scene(vbox1, 500, 500);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Culminating Project");
    primaryStage.show();

    /**
     * ************************ SCENE 2 WORK *************************
     */

    //THIS IS ROUGH WORK SO FAR
    //Here, testing out new scene to see that it loads properly (and it does)
    Circle testCircle = new Circle();
    testCircle.setRadius(30);
    testCircle.setFill(Color.YELLOW);
    StackPane testPane = new StackPane(testCircle, testLabel);

    Scene scene2 = new Scene(testPane, 500, 500);

    /**
     * ************************ EVENTS *************************
     */

    //Stores user-entered name and prompts for user gender. Adds Continue button
    enterNameBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {

            if ((count < 1) && (!nameTextField.getText().isEmpty())) {
                name = nameTextField.getText();
                genderLabel.setText("Hi " + name + "! Please select whether        you are a boy or girl.");

                genderBtnBox.getChildren().addAll(rb1, rb2);
                vbox1.getChildren().add(goToScene2Btn);
                count++;
            }
        }
    });

    //When pressed, changes the scene so that scene 2 is set instead
    goToScene2Btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            primaryStage.setScene(scene2);
        }

    });

    //Radio button selection is stored in gender variable
    genderGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        @Override
        public void changed(ObservableValue<? extends Toggle> ov,
                Toggle old_toggle, Toggle new_toggle) {
            if (genderGroup.getSelectedToggle() != null) {

                gender = genderGroup.getSelectedToggle().getUserData().toString();
                testLabel.setText(gender + " has been selected");

            }
        }
    });

    if (gender.equals("boy")){
        { 

        }
    }
    else if (gender.equals("girl")){ 
        { 

        }
    }


}

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

}

Now I have another class called CharacterGraphic, which I want to call and make the graphic I created in it appear.

package culminating;
& all the other imports

public class CharacterGraphic extends Culminating_JavaFX {

public void start(Stage primaryStage) throws Exception {

    String gender = "boy"; 

    Pane pane = new Pane();
    pane.setStyle("-fx-background-color: LIGHTBLUE");
    pane.setPrefSize(200, 200);

    Circle head = new Circle();
    head.setRadius(50);
    head.setCenterX(240);
    head.setCenterY(120);
    head.setFill(Color.BURLYWOOD);

    etc etc (all other graphics i made)

How do I do this???? And where would I do this?? Any answers really, really appreciated!

Lia
  • 45
  • 1
  • 1
  • 8
  • 1
    You should not have two `Application` subclasses and two `start(...)` methods in the same application (`start()` is the method that starts the application; it is only started once). Your structure is basically pretty badly wrong (why is `CharacterGraphic` a subclass of `Culminating_JavaFX`, for example?). See if http://stackoverflow.com/questions/32464698/ helps at all. – James_D Jan 10 '16 at 02:35

0 Answers0