java - JavaFX 传递参数
问题描述
我创建了以下类:
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);
}
}
在secureCAController 中,初始化代理并启动应用程序,但是当我尝试执行一种方法时,例如myAgent.getname() 返回null。
任何人都可以帮助我吗?我不太了解 javafx 抱歉,如果它是一个虚拟错误。
myAgent 是一个对象,它包含很多方法。
我的 fxml 如下:
<?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>
解决方案
我已经清理了你的项目:
你的应用类:
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);
}
}
您的 FXML 文件:
<?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>
还有你的控制器类:
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();
}
}
也许这会对你有所帮助..
如果您想将 myAgent 从应用程序类传递给控制器类。您的 Application 类必须如下所示。而且您必须为控制器类中的 myAgent 变量创建一个设置器。
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);
}
}
推荐阅读
- python - Lambda 错误:未找到模块。Cryptography.hamtaz.bindings._constant_time
- android - 使用 decodeByteArray 解码 h264 视频帧总是返回 null
- html - 将 HTML 元素的位置更改为绝对位置是否也会更改元素的内容类别?
- javascript - 如何在另一个函数的函数内使用数组中的值?
- ruby-on-rails - 在 Rails 上找不到没有 ID ruby 的 Beat
- javascript - 如何让一个圆圈出现在任何颜色的 html5 画布上
- c - 计算poly CRC-32K/6.2的CRC查找表
- php - ajax 接收来自 php 的响应但不能与 ajax 一起使用
- vue.js - 如何使用 v-select 获取值,使用插槽模板从 ajax 加载的选项
- arrays - 在 3D numpy 矩阵中重塑张量