1

I create the following class:

    package sample;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXPasswordField;
import com.jfoenix.controls.JFXTextArea;
import com.jfoenix.controls.JFXTextField;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import vom.CAPlatform;

public class SecureCAController extends Application {

    private double xOffset;
    private double yOffset;
    public CAPlatform myAgent;
    public static boolean ready = false;

    public SecureCAController(CAPlatform caPlatform) {
        myAgent = caPlatform;
        System.out.println(myAgent.getAID());
    }

    public SecureCAController() {

    }

    public void show(){
        launch();
    }


    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));


        root.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                xOffset = mouseEvent.getSceneX();
                yOffset = mouseEvent.getSceneY();
            }
        });


        root.setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                primaryStage.setX(mouseEvent.getScreenX() - xOffset);
                primaryStage.setY(mouseEvent.getScreenY() - yOffset);
            }
        });


        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.setTitle("CA");
        Scene sceneNew = new Scene(root);
        sceneNew.setFill(Color.TRANSPARENT);
        primaryStage.setScene(sceneNew);
        primaryStage.show();
        ready = true;
    }


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


    public void setAgent(CAPlatform caPlatform) {
        myAgent = caPlatform;
    }

    @FXML
    private ImageView userArrow;
    @FXML private ImageView printerArrow;
    @FXML private ImageView crudArrow;
    @FXML private ImageView exitArrow;

    @FXML private AnchorPane userPanel;
    @FXML private AnchorPane printerPanel;
    @FXML private AnchorPane crudPanel;

    @FXML private JFXTextField userText;
    @FXML private JFXPasswordField passwordText;
    @FXML private JFXTextField AIDText;

    @FXML private JFXButton startButton;
    @FXML private JFXButton pendingButton;
    @FXML private JFXButton validateButton;
    @FXML private JFXButton validateRButton;

    @FXML private JFXTextArea PList;
    @FXML private JFXTextArea AreaList;


    public void onstartButton(ActionEvent event){
        if(userText.getText().isEmpty() || passwordText.getText().isEmpty()){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("ERROR");
            alert.setContentText("PLEASE INSERT USERNAME AND PASSWORD");
        }else{
            System.out.println(this.myAgent.getAID());
        }
    }

    public void onpendingButton(ActionEvent event){

    }

    public void onvalidateButton(ActionEvent event){
        if(AIDText.getText().isEmpty()){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("ERROR");
            alert.setContentText("PLEASE INSERT AN AID");
        }
    }

    public void onvalidateRButton(ActionEvent event){

    }



    public void onExitButtonClicked(MouseEvent event){
        Platform.exit();
        System.exit(0);
    }


    public void onUserButtonClicked(MouseEvent event){
        System.out.println("si");
        userPanel.setVisible(true);
        userArrow.setVisible(true);

        printerPanel.setVisible(false);
        crudPanel.setVisible(false);
        printerArrow.setVisible(false);
        crudArrow.setVisible(false);
        exitArrow.setVisible(false);
    }

    public void onPrinterButtonClicked(MouseEvent event){
        printerPanel.setVisible(true);
        printerArrow.setVisible(true);

        crudPanel.setVisible(false);
        userPanel.setVisible(false);
        userArrow.setVisible(false);
        crudArrow.setVisible(false);
        exitArrow.setVisible(false);
    }

    public void onCRUDButtonClicked(MouseEvent event){
        crudPanel.setVisible(true);
        crudArrow.setVisible(true);

        userPanel.setVisible(false);
        userArrow.setVisible(false);
        printerPanel.setVisible(false);
        printerArrow.setVisible(false);
        exitArrow.setVisible(false);
    }

}

In the secureCAController, initialize the agent and launch the application, but when i try to execute one method for example myAgent.getname() return null.

Anyone can help me? I dont know a lot of about javafx sorry if it is a dummy error.

myAgent is an object, that contains a lot of methods.

My fxml is the following:

    <?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextArea?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="474.0" prefWidth="562.0" style="-fx-background-color: #85c0cc;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.SecureCAController">
   <children>
      <AnchorPane prefHeight="0.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;">
         <children>
            <HBox prefHeight="63.0" prefWidth="562.0">
               <children>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onUserButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/user.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onPrinterButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/print.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onCRUDButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/accept.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onExitButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/exit.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
               </children>
            </HBox>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="userPanel" layoutY="86.0" prefHeight="398.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;">
         <children>
            <AnchorPane layoutX="20.0" layoutY="28.0" prefHeight="280.0" prefWidth="522.0" style="-fx-background-color: #85c0cc;" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0">
               <children>
                  <Label layoutX="60.0" layoutY="126.0" prefHeight="26.0" prefWidth="120.0" text="     USER:">
                     <font>
                        <Font name="SansSerif Bold" size="20.0" />
                     </font>
                  </Label>
                  <Label layoutX="57.0" layoutY="191.0" text="PASSWORD:">
                     <font>
                        <Font name="SansSerif Bold Italic" size="20.0" />
                     </font>
                  </Label>
                  <JFXTextField fx:id="userText" layoutX="228.0" layoutY="126.0" prefHeight="27.0" prefWidth="236.0" promptText="Enter your username" />
                  <ImageView fitHeight="100.0" fitWidth="100.0" layoutX="220.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/shelt.png" />
                     </image>
                  </ImageView>
                  <JFXPasswordField fx:id="passwordText" layoutX="228.0" layoutY="189.0" prefHeight="27.0" prefWidth="236.0" promptText="Enter your password" />
               </children>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
            </AnchorPane>
            <JFXButton fx:id="startButton" layoutX="203.0" layoutY="337.0" onAction="#onstartButton" prefHeight="27.0" prefWidth="157.0" style="-fx-background-color: #85c0cc;" text="Start">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
         </children>
      </AnchorPane>
      <ImageView fx:id="userArrow" fitHeight="30.0" fitWidth="90.0" layoutX="83.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <ImageView fx:id="printerArrow" fitHeight="30.0" fitWidth="90.0" layoutX="208.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0" visible="false">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <ImageView fx:id="crudArrow" fitHeight="30.0" fitWidth="90.0" layoutX="327.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0" visible="false">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <ImageView fx:id="exitArrow" fitHeight="30.0" fitWidth="90.0" layoutX="444.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0" visible="false">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <AnchorPane fx:id="printerPanel" layoutX="10.0" layoutY="96.0" prefHeight="398.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="86.0">
         <children>
            <AnchorPane layoutX="20.0" layoutY="28.0" prefHeight="280.0" prefWidth="522.0" style="-fx-background-color: #85c0cc;" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <children>
                  <Separator layoutY="24.0" prefHeight="3.0" prefWidth="522.0" style="-fx-background-color: #000000;" />
                  <Label layoutX="203.0" layoutY="2.0" text="Platform List" textAlignment="CENTER">
                     <font>
                        <Font name="SansSerif Regular" size="20.0" />
                     </font>
                  </Label>
                  <JFXTextArea fx:id="AreaList" layoutY="27.0" prefHeight="252.0" prefWidth="523.0" />
               </children>
            </AnchorPane>
            <JFXButton fx:id="pendingButton" layoutX="20.0" layoutY="334.0" onAction="#onpendingButton" prefHeight="40.0" prefWidth="222.0" style="-fx-background-color: #85c0cc;" text="Pending Requests">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
            <JFXButton fx:id="validateRButton" layoutX="320.0" layoutY="334.0" onAction="#onvalidateRButton" prefHeight="40.0" prefWidth="222.0" style="-fx-background-color: #85c0cc;" text="Validated Requests">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="crudPanel" layoutX="20.0" layoutY="106.0" prefHeight="398.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="86.0">
         <children>
            <AnchorPane layoutX="20.0" layoutY="28.0" prefHeight="280.0" prefWidth="522.0" style="-fx-background-color: #85c0cc;" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <children>
                  <Separator layoutY="24.0" prefHeight="3.0" prefWidth="522.0" style="-fx-background-color: #000000;" />
                  <Label layoutX="184.0" layoutY="2.0" text="Pending Platforms" textAlignment="CENTER">
                     <font>
                        <Font name="SansSerif Regular" size="20.0" />
                     </font>
                  </Label>
                  <JFXTextArea fx:id="PList" layoutY="27.0" prefHeight="252.0" prefWidth="523.0" />
               </children>
            </AnchorPane>
            <JFXButton fx:id="ValidateButton" layoutX="322.0" layoutY="333.0" onAction="#onvalidateButton" prefHeight="40.0" prefWidth="219.0" style="-fx-background-color: #85c0cc;" text="Validate">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
            <JFXTextField fx:id="AIDText" focusColor="BLACK" layoutX="20.0" layoutY="344.0" prefHeight="27.0" prefWidth="290.0" unFocusColor="WHITE" />
            <Label layoutX="19.0" layoutY="333.0" text="PLATFORM AID:" textFill="WHITE" />
         </children>
      </AnchorPane>
   </children>
</AnchorPane>
Esteban
  • 31
  • 1
  • 6
  • Can you also post your FXML File and your CAPlatform Class? – micpog90 May 24 '20 at 18:08
  • It’s pretty much always a mistake to use the same class for the application Life cycle (I.e. the `Application` subclass) as you use for your controller. Anyway, though, both the instance created for you when you call `Application.launch()` and the instance of the controller created when the FXML file is loaded are created by invoking the zero-argument constructor. That constructor doesn’t initialize `myAgent`, so it will be null (in both cases). – James_D May 24 '20 at 18:23
  • @James_D and its possible to initialize this object? – Esteban May 24 '20 at 18:26
  • The problem is that you should split the Controller Class and the Application Class apart. Then the Controller Class implements Initailizable and in the intitialize method you can initialize myAgent.. – micpog90 May 24 '20 at 18:39
  • @micpog90 i just divide the controller and the application, but how can i acces to the myAgent? – Esteban May 24 '20 at 18:43
  • If needed, you can initialize it in the `start()` method and [pass it to the controller](https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml). Or, if it’s ok to have a different instance for each controller that’s created, just initialize it in the controller using one of the two ways shown in the answer by @micpog90 – James_D May 24 '20 at 18:53
  • I have added to the answer how you could pass myAgent from the Application to the Controller.. – micpog90 May 24 '20 at 18:59

1 Answers1

1

I have cleaned up your project a little:

Your Aplication Class:

package vom;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author mipog
 */
public class SecureCA extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("SecureCA.fxml"));

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

Your FXML-File:

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextArea?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="474.0" prefWidth="562.0" style="-fx-background-color: #85c0cc;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="vom.SecureCAController">
   <children>
      <AnchorPane prefHeight="0.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;">
         <children>
            <HBox prefHeight="63.0" prefWidth="562.0">
               <children>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onUserButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/user.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onPrinterButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/print.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onCRUDButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/accept.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
                  <ImageView fitHeight="46.0" fitWidth="69.0" onMouseClicked="#onExitButtonClicked" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/exit.png" />
                     </image>
                     <HBox.margin>
                        <Insets top="10.0" />
                     </HBox.margin>
                  </ImageView>
                  <Separator prefWidth="200.0" visible="false" />
               </children>
            </HBox>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="userPanel" layoutY="86.0" prefHeight="398.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;">
         <children>
            <AnchorPane layoutX="20.0" layoutY="28.0" prefHeight="280.0" prefWidth="522.0" style="-fx-background-color: #85c0cc;" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0">
               <children>
                  <Label layoutX="60.0" layoutY="126.0" prefHeight="26.0" prefWidth="120.0" text="     USER:">
                     <font>
                        <Font name="SansSerif Bold" size="20.0" />
                     </font>
                  </Label>
                  <Label layoutX="57.0" layoutY="191.0" text="PASSWORD:">
                     <font>
                        <Font name="SansSerif Bold Italic" size="20.0" />
                     </font>
                  </Label>
                  <JFXTextField fx:id="userText" layoutX="228.0" layoutY="126.0" prefHeight="27.0" prefWidth="236.0" promptText="Enter your username" />
                  <ImageView fitHeight="100.0" fitWidth="100.0" layoutX="220.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Images/shelt.png" />
                     </image>
                  </ImageView>
                  <JFXPasswordField fx:id="passwordText" layoutX="228.0" layoutY="189.0" prefHeight="27.0" prefWidth="236.0" promptText="Enter your password" />
               </children>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
            </AnchorPane>
            <JFXButton fx:id="startButton" layoutX="203.0" layoutY="337.0" onAction="#onstartButton" prefHeight="27.0" prefWidth="157.0" style="-fx-background-color: #85c0cc;" text="Start">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
         </children>
      </AnchorPane>
      <ImageView fx:id="userArrow" fitHeight="30.0" fitWidth="90.0" layoutX="83.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <ImageView fx:id="printerArrow" fitHeight="30.0" fitWidth="90.0" layoutX="208.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0" visible="false">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <ImageView fx:id="crudArrow" fitHeight="30.0" fitWidth="90.0" layoutX="327.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0" visible="false">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <ImageView fx:id="exitArrow" fitHeight="30.0" fitWidth="90.0" layoutX="444.0" layoutY="59.0" pickOnBounds="true" preserveRatio="true" rotate="180.0" visible="false">
         <image>
            <Image url="@Images/arrow.png" />
         </image>
      </ImageView>
      <AnchorPane fx:id="printerPanel" layoutX="10.0" layoutY="96.0" prefHeight="398.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="86.0">
         <children>
            <AnchorPane layoutX="20.0" layoutY="28.0" prefHeight="280.0" prefWidth="522.0" style="-fx-background-color: #85c0cc;" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <children>
                  <Separator layoutY="24.0" prefHeight="3.0" prefWidth="522.0" style="-fx-background-color: #000000;" />
                  <Label layoutX="203.0" layoutY="2.0" text="Platform List" textAlignment="CENTER">
                     <font>
                        <Font name="SansSerif Regular" size="20.0" />
                     </font>
                  </Label>
                  <JFXTextArea fx:id="AreaList" layoutY="27.0" prefHeight="252.0" prefWidth="523.0" />
               </children>
            </AnchorPane>
            <JFXButton fx:id="pendingButton" layoutX="20.0" layoutY="334.0" onAction="#onpendingButton" prefHeight="40.0" prefWidth="222.0" style="-fx-background-color: #85c0cc;" text="Pending Requests">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
            <JFXButton fx:id="validateRButton" layoutX="320.0" layoutY="334.0" onAction="#onvalidateRButton" prefHeight="40.0" prefWidth="222.0" style="-fx-background-color: #85c0cc;" text="Validated Requests">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
         </children>
      </AnchorPane>
      <AnchorPane fx:id="crudPanel" layoutX="20.0" layoutY="106.0" prefHeight="398.0" prefWidth="562.0" style="-fx-background-color: #0f6b7d;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="86.0">
         <children>
            <AnchorPane layoutX="20.0" layoutY="28.0" prefHeight="280.0" prefWidth="522.0" style="-fx-background-color: #85c0cc;" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <children>
                  <Separator layoutY="24.0" prefHeight="3.0" prefWidth="522.0" style="-fx-background-color: #000000;" />
                  <Label layoutX="184.0" layoutY="2.0" text="Pending Platforms" textAlignment="CENTER">
                     <font>
                        <Font name="SansSerif Regular" size="20.0" />
                     </font>
                  </Label>
                  <JFXTextArea fx:id="PList" layoutY="27.0" prefHeight="252.0" prefWidth="523.0" />
               </children>
            </AnchorPane>
            <JFXButton fx:id="ValidateButton" layoutX="322.0" layoutY="333.0" onAction="#onvalidateButton" prefHeight="40.0" prefWidth="219.0" style="-fx-background-color: #85c0cc;" text="Validate">
               <font>
                  <Font size="20.0" />
               </font>
            </JFXButton>
            <JFXTextField fx:id="AIDText" focusColor="BLACK" layoutX="20.0" layoutY="344.0" prefHeight="27.0" prefWidth="290.0" unFocusColor="WHITE" />
            <Label layoutX="19.0" layoutY="333.0" text="PLATFORM AID:" textFill="WHITE" />
         </children>
      </AnchorPane>
   </children>
</AnchorPane>

And your Controller Class:

package vom;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXPasswordField;
import com.jfoenix.controls.JFXTextArea;
import com.jfoenix.controls.JFXTextField;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;

/**
 *
 * @author mipog
 */
public class SecureCAController implements Initializable {

    @FXML
    private ImageView userArrow;
    @FXML
    private ImageView printerArrow;
    @FXML
    private ImageView crudArrow;
    @FXML
    private ImageView exitArrow;

    @FXML
    private AnchorPane userPanel;
    @FXML
    private AnchorPane printerPanel;
    @FXML
    private AnchorPane crudPanel;

    @FXML
    private JFXTextField userText;
    @FXML
    private JFXPasswordField passwordText;
    @FXML
    private JFXTextField AIDText;

    @FXML
    private JFXButton startButton;
    @FXML
    private JFXButton pendingButton;
    @FXML
    private JFXButton validateButton;
    @FXML
    private JFXButton validateRButton;

    @FXML
    private JFXTextArea PList;
    @FXML
    private JFXTextArea AreaList;

    //You can either here init your myAgent or in the initialize method
    CAPlatform myAgent = new CAPlatform();

    @FXML
    private void onstartButton() {
        if (userText.getText().isEmpty() || passwordText.getText().isEmpty()) {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("ERROR");
            alert.setContentText("PLEASE INSERT USERNAME AND PASSWORD");
        } else {
            System.out.println(this.myAgent.getAID());
        }
    }

    @FXML
    private void onpendingButton() {

    }

    @FXML
    private void onvalidateButton() {
        if (AIDText.getText().isEmpty()) {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("ERROR");
            alert.setContentText("PLEASE INSERT AN AID");
        }
    }

    @FXML
    private void onvalidateRButton() {

    }

    @FXML
    private void onExitButtonClicked() {
        Platform.exit();
        System.exit(0);
    }

    @FXML
    private void onUserButtonClicked() {
        System.out.println("si");
        userPanel.setVisible(true);
        userArrow.setVisible(true);

        printerPanel.setVisible(false);
        crudPanel.setVisible(false);
        printerArrow.setVisible(false);
        crudArrow.setVisible(false);
        exitArrow.setVisible(false);
    }

    @FXML
    private void onPrinterButtonClicked() {
        printerPanel.setVisible(true);
        printerArrow.setVisible(true);

        crudPanel.setVisible(false);
        userPanel.setVisible(false);
        userArrow.setVisible(false);
        crudArrow.setVisible(false);
        exitArrow.setVisible(false);
    }

    @FXML
    private void onCRUDButtonClicked() {
        crudPanel.setVisible(true);
        crudArrow.setVisible(true);

        userPanel.setVisible(false);
        userArrow.setVisible(false);
        printerPanel.setVisible(false);
        printerArrow.setVisible(false);
        exitArrow.setVisible(false);
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // Here you init you myAgent
        myAgent = new CAPlatform();
    }

}

Maybe this will help you a little..

if you want to pass myAgent to the Controller Class from the Application Class. Your Application class has to look like the following. And you have to make a setter for the myAgent variable in the Controller Class.

package vom;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author mipog
 */
public class SecureCA extends Application {

    CAPlatform myAgent = new CAPlatform();

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("SecureCA.fxml"));
        Parent root = loader.load();

        Scene scene = new Scene(root);

        SecureCAController controller = loader.getController();
        controller.setMyAgent(myAgent);

        stage.setScene(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}
micpog90
  • 106
  • 8
  • Thank you so much @micpog90. but this solution create a new caagent and not that i want.It would be very difficult to do as I say? – Esteban May 24 '20 at 18:59
  • You can pass the 'caagent' from the application to the controller if you have initialized it there. Unfortunately, I have not your whole project, so I have no idea where you init the myAgent variable.. – micpog90 May 24 '20 at 19:02
  • In the secureCAController i create the function to pass the agent and initialize the var, if i print it, its correct but when i save it and then reference it is null :( – Esteban May 24 '20 at 19:14
  • how i should call the Application from the CAPlatform? – Esteban May 24 '20 at 19:16
  • What to you mean with save it? – micpog90 May 24 '20 at 19:20
  • I just fix it, THANK YOU SO MUCH @micpog90 really, thanks for everything – Esteban May 24 '20 at 19:25