Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaFX中,如何从主类调用图形类?_Java_Class_Javafx_Javafx 2_Instance - Fatal编程技术网

在JavaFX中,如何从主类调用图形类?

在JavaFX中,如何从主类调用图形类?,java,class,javafx,javafx-2,instance,Java,Class,Javafx,Javafx 2,Instance,我是一个非常新的程序员,所以如果这个问题听起来很愚蠢的话,我不会回答,但是 这是我的主要观点: package culminating; import javafx.application.Application; &所有其他必要的进口 public class CulminatingMAIN extends Application { //Set Global variables int count = 0; String name; String gender = "Boy"; Lab

我是一个非常新的程序员,所以如果这个问题听起来很愚蠢的话,我不会回答,但是

这是我的主要观点:

package culminating;

import javafx.application.Application;
&所有其他必要的进口

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);
}

我该怎么做????我在哪里做这个??任何答案都非常感谢

同一个应用程序中不应该有两个
Application
子类和两个
start(…)
方法(
start()
是启动应用程序的方法;它只启动一次)。您的结构基本上是非常错误的(例如,为什么
CharacterGraphic
的一个子类,最终导致了_JavaFX
)。看看是否有帮助。在同一个应用程序中,不应该有两个
应用程序
子类和两个
启动(…)
方法(
启动()
是启动应用程序的方法;它只启动一次)。您的结构基本上是非常错误的(例如,为什么
CharacterGraphic
的一个子类,最终导致了_JavaFX
)。看看是否有帮助。
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)