I am new to programming. My problem right now is that I want to ask the user to give his name in a TextField, and use that value(name) in another BoardGame class. for example, first window to ask his name, and second window to use it in the game.
My View class (first window)
public class View extends BorderPane {
public TextArea player1;
public Label name1;
public View(){
super();
initializeNodes();
layoutNodes();
}
public void initializeNodes() {
player1 = new TextArea();
name1 = new Label ("Player 1: ");
}
public void layoutNodes() {
player1.setPrefSize(100,20);
naam1.setPrefSize(60,40);
HBox hBox = new HBox(name1,player1);
TextField nameField;
nameField = new TextField();
nameField.setPrefHeight(70);
player1.getText();
}
EventHandler<ActionEvent> e = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
player1.setText(name1.getText());
}
};
public TextArea getPlayer1() {
return player1;
}
My BoardGame class(second window) :
public class Boardgame extends BorderPane{
private Label lblPlayer1;
private View view;
public Boardgame(){
super();
initializeNodes();
layoutNodes();
}
private void initializeNodes() {
super.setPrefSize(900,700);
lblPlayer1 = new Label("Player 1");
}
private void layoutNodes() {
VBox vBox = new VBox(lblPlayer1);
}
Only thing that works is where I get "Player 1" instead of the name, because I put it hardcoded in there, but how can I make it their input(name)?