Write a JavaFX program that meets the following requirements 1) With your demonstration class, Implement a graphical window to display a game character setup dialog to allow the user to enter data into a visible window in order to set up the character object for the game (a) The dialog must provide a separate visual field for each data field, and include a textual label to the left of each field.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class GUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Label nameLabel = new Label("Name:");
Label weaponLabel = new Label("Weapon:");
Label healthLabel = new Label("Health:");
TextField nameTextField = new TextField();
TextField weaponTextField = new TextField();
TextField healthTextField = new TextField();
GridPane gridPane = new GridPane();
gridPane.addRow(0,nameLabel);
gridPane.addRow(1,weaponLabel);
gridPane.addRow(2,healthLabel);
gridPane.addColumn(1,nameTextField);
gridPane.addColumn(1,weaponTextField);
gridPane.addColumn(1,healthTextField);
primaryStage.setScene(new Scene(gridPane));
primaryStage.setTitle("Character Setup");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Comments
Leave a comment