NullpointerException error while editing any component inside panel [duplicate] - java

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Passing Parameters JavaFX FXML
(10 answers)
Closed 4 years ago.
I'm trying to change the text of a label inside a panel, but whenever I try to make any changes in the components of that panel I get the error NullPointer.
My program works with a worksheet to store the data and show to the user
FXMLDocumetController.java (I used the 'alterarTela(int tela)' method to switch between panels):
package agenda;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXListView;
import com.jfoenix.controls.JFXTextField;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
public class FXMLDocumentController implements Initializable {
#FXML
private AnchorPane paneFundo;
#FXML
private JFXListView<Label> listView;
#FXML
private JFXTextField txtPesquisar;
#FXML
private JFXButton btnPesquisar;
#FXML
private JFXButton FAB;
ArrayList <String> urlTelas = new ArrayList<String>();
Arquivo arquivo = new Arquivo();
PaneInfoPessoa paneInfoPessoa = new PaneInfoPessoa();
PaneInfoPA paneInfoPa = new PaneInfoPA();
#FXML
public void btnPesquisarClique (ActionEvent e) {
}
#FXML
public void FABClique (ActionEvent e) throws IOException {
System.out.println("Tela add abrir");
alterarTela(2);
}
#FXML
public void itemListaSelecionado() {
String nome[] = listView.getSelectionModel().getSelectedItem().getText().split("\n");
if (nome[0].startsWith("PA")) {
alterarTela(1);
System.out.println("Tela alterada 1");
paneInfoPa.atualizarDados(arquivo.pegarPaLista(nome[0]));
} else {
alterarTela(0);
System.out.println("Tela alterada 0");
paneInfoPessoa.atualizarDados(arquivo.pegarPessoaLista(nome[0]));
}
}
public void alterarTela(int tela) {
try {
Pane pane = FXMLLoader.load(getClass().getResource(urlTelas.get(tela)));
paneFundo.getChildren().setAll(pane);
} catch (IOException e) {
System.out.print("Erro na função alterar tela " + e);
}
}
#Override
public void initialize(URL url, ResourceBundle rb) {
urlTelas.add("PaneInfoPessoa.fxml");
urlTelas.add("PaneInfoPA.fxml");
urlTelas.add("PaneAdd.fxml");
listView.setItems(arquivo.lerPlanilha(0, true));
listView.setFixedCellSize(60);
listView.setFocusTraversable(false);
listView.getSelectionModel().selectedItemProperty().addListener(
(Observable, oldValue, newValue) -> itemListaSelecionado());
}
}
Arquivo.java (to set and get data from worksheet):
package agenda;
import java.util.ArrayList;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Label;
import jxl.Sheet;
public class Arquivo {
private List<Label> listaContatos = new ArrayList<>();
private ObservableList<Label> obsListaContatos;
public ObservableList<Label> lerPlanilha(int num_planilha, boolean lerTodas) {
if (lerTodas) {
try {
int contPlanilhas = Agenda.workbook.getNumberOfSheets();
for (int j = 0; j < contPlanilhas; j++ ) {
List<Label> listaContatos2 = new ArrayList<>();
Sheet planilha = Agenda.workbook.getSheet(j);
int linhas = planilha.getRows();
for (int i = 0; i < linhas; i++) {
String colunaNome = planilha.getCell(0, i).getContents();
String colunaFixo = planilha.getCell(2, i).getContents();
listaContatos2.add(new Label(colunaNome + "\n" + colunaFixo));
}
//TODO ordenar
listaContatos.addAll(listaContatos2);
}
obsListaContatos = FXCollections.observableArrayList(listaContatos);
return obsListaContatos;
} catch (Exception e) {
System.out.println("Erro na função lerPlanilha" + e.toString());
return null;
}
} else {
try {
Sheet planilha = Agenda.workbook.getSheet(num_planilha);
int linhas = planilha.getRows();
for (int i = 0; i < linhas; i++) {
String colunaNome = planilha.getCell(0, i).getContents();
String colunaFixo = planilha.getCell(2, i).getContents();
listaContatos.add(new Label(colunaNome + "\n" + colunaFixo));
}
obsListaContatos = FXCollections.observableArrayList(listaContatos);
return obsListaContatos;
} catch (Exception e) {
System.out.println("Erro na função lerPlanilha" + e.toString());
return null;
}
}
}
public Pessoa pegarPessoaLista(String nome) {
int linhaSel = -1;
Pessoa pessoa = new Pessoa();
Sheet planilha = Agenda.workbook.getSheet(1);
int linhas = planilha.getRows();
for (int i = 0; i < linhas; i++) {
if (planilha.getCell(0, i).getContents().equals(nome)) {
linhaSel = i;
}
}
if (linhaSel >= 0) {
pessoa.setNome(planilha.getCell(0, linhaSel).getContents());
pessoa.setRamal(planilha.getCell(1, linhaSel).getContents());
pessoa.setCelular(planilha.getCell(2, linhaSel).getContents());
pessoa.setTelefone(planilha.getCell(3, linhaSel).getContents());
pessoa.setPa(planilha.getCell(4, linhaSel).getContents());
pessoa.setSetor(planilha.getCell(5, linhaSel).getContents());
pessoa.setEmail(planilha.getCell(6, linhaSel).getContents());
return pessoa;
} else {
pessoa.setNome("Erro");
pessoa.setPa("");
pessoa.setCelular("");
pessoa.setTelefone("");
pessoa.setRamal("");
pessoa.setSetor("");
pessoa.setEmail("");
System.out.println("Pessoa não encontrada na funcao arquivo.pegarPessoaLista");
return pessoa;
}
}
public Pessoa pegarPessoaPesquisa() {
return null;
}
public Pa pegarPaLista(String pa) {
int linhaSel = -1;
Pa PA = new Pa();
Sheet planilha = Agenda.workbook.getSheet(0);
int linhas = planilha.getRows();
for (int i = 0; i < linhas; i++) {
if (planilha.getCell(0, i).getContents().equals(pa)) {
linhaSel = i;
}
}
if (linhaSel >= 0) {
PA.setNumero(planilha.getCell(0, linhaSel).getContents());
PA.setRamal(planilha.getCell(1, linhaSel).getContents());
PA.setFixo1(planilha.getCell(2, linhaSel).getContents());
PA.setFixo2(planilha.getCell(3, linhaSel).getContents());
PA.setCelular(planilha.getCell(4, linhaSel).getContents());
PA.setContPessoas(planilha.getCell(5, linhaSel).getContents());
PA.setGerente(planilha.getCell(6, linhaSel).getContents());
PA.setLocal(planilha.getCell(0, linhaSel).getContents());
System.out.println("Pa selecionado" + PA.getNumero());
return PA;
} else {
PA.setNumero("Erro");
PA.setRamal("");
PA.setFixo1("");
PA.setFixo2("");
PA.setCelular("");
PA.setContPessoas("");
PA.setGerente("");
PA.setLocal("");
System.out.println("Pessoa não encontrada na funcao arquivo.pegarPessoaLista");
return PA;
}
}
public Pa pegarPaPesquisa() {
return null;
}
}
PaneInfoPa.java (fx controller of PaneInfoPa.FXML):
package agenda;
import com.jfoenix.controls.JFXButton;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
public class PaneInfoPA {
#FXML
private JFXButton btnEditar;
#FXML
private JFXButton btnRemover;
#FXML
private Label txtNumero;
#FXML
private Label txtRamal;
#FXML
private Label txtTelefone;
#FXML
private Label txtTelefone2;
#FXML
private Label txtCelular;
#FXML
private Label txtContPessoas;
#FXML
private Label txtGerente;
#FXML
private void initialize() {
System.out.println("Iniciando tela");
txtNumero.setText("--");
txtRamal.setText("--");
txtTelefone.setText("--");
txtTelefone2.setText("--");
txtCelular.setText("--");
txtContPessoas.setText("--");
txtGerente.setText("--");
System.out.println("tela iniciada");
}
public void atualizarDados(Pa pa) {
System.out.println("Alterando Valores do pane info pa - " + pa.getNumero());
btnEditar.setDisable(true);
//txtNumero.setText(pa.getNumero());
/*txtRamal.setText(pa.getRamal());
txtTelefone.setText(pa.getFixo1());
txtTelefone2.setText(pa.getFixo2());
txtCelular.setText(pa.getCelular());
txtContPessoas.setText(pa.getContPessoas());
txtGerente.setText(pa.getGerente());*/
System.out.println("Valores do pane info pa atualizados");
}
#FXML
public void txtGerenteClique(ActionEvent event) {
System.out.println("btn editar clique");
}
#FXML
public void btnEditarClique(ActionEvent event) {
System.out.println("btn editar clique");
}
#FXML
public void btnRemoverClique(ActionEvent event) {
System.out.println("btn remover clique");
}
}
PaneInfoPa.FXML (
I already checked all fx: id of FXML):
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import com.jfoenix.controls.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="437.0" prefWidth="418.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="agenda.PaneInfoPA">
<children>
<Pane layoutX="23.0" layoutY="18.0" prefHeight="400.0" prefWidth="376.0" style="-fx-background-color: #ffffff; -fx-background-radius: 5 5 5 5;">
<effect>
<DropShadow color="#00000037" />
</effect>
<children>
<Pane layoutX="18.0" layoutY="240.0" prefHeight="55.0" prefWidth="188.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Celular" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtCelular" layoutX="10.0" layoutY="27.0" prefHeight="24.0" prefWidth="161.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children>
</Pane>
<Pane layoutX="15.0" layoutY="84.0" prefHeight="55.0" prefWidth="261.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Número / Local" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtNumero" layoutX="10.0" layoutY="26.0" prefHeight="24.0" prefWidth="241.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children></Pane>
<Label layoutX="18.0" layoutY="23.0" text="Informações">
<font>
<Font name="Segoe UI" size="22.0" />
</font>
</Label>
<Separator layoutX="15.0" layoutY="57.0" prefHeight="10.0" prefWidth="339.0" />
<JFXButton fx:id="btnEditar" layoutX="213.0" layoutY="22.0" onAction="#btnEditarClique" prefHeight="27.0" prefWidth="66.0" ripplerFill="#c6c6c6" text="Editar" textFill="#16a085">
<font>
<Font name="Segoe UI Semibold" size="13.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnRemover" layoutX="282.0" layoutY="22.0" onAction="#btnRemoverClique" prefHeight="27.0" prefWidth="74.0" ripplerFill="#cdcdcd" text="Remover" textFill="#e74c3c">
<font>
<Font name="Segoe UI Semibold" size="13.0" />
</font>
</JFXButton>
<Pane layoutX="15.0" layoutY="163.0" prefHeight="55.0" prefWidth="161.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Telefone 1" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtTelefone" layoutX="10.0" layoutY="27.0" prefHeight="22.0" prefWidth="144.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children>
</Pane>
<Pane layoutX="191.0" layoutY="163.0" prefHeight="55.0" prefWidth="167.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Telefone 2" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtTelefone2" layoutX="10.0" layoutY="27.0" prefHeight="22.0" prefWidth="144.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children>
</Pane>
<Pane layoutX="287.0" layoutY="84.0" prefHeight="55.0" prefWidth="66.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Ramal" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtRamal" layoutX="10.0" layoutY="27.0" prefHeight="24.0" prefWidth="46.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children>
</Pane>
<Pane layoutX="225.0" layoutY="240.0" prefHeight="55.0" prefWidth="131.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Nº de pessoas" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtContPessoas" layoutX="10.0" layoutY="27.0" prefHeight="24.0" prefWidth="103.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children>
</Pane>
<Pane layoutX="18.0" layoutY="319.0" prefHeight="55.0" prefWidth="261.0" style="-fx-background-color: fafafa; -fx-background-radius: 5 5 5 5;">
<children>
<Label layoutX="10.0" layoutY="5.0" text="Gerente" textFill="#16a085">
<font>
<Font name="Segoe UI" size="15.0" />
</font>
</Label>
<Label fx:id="txtGerente" layoutX="10.0" layoutY="27.0" onMouseClicked="#txtGerenteClique" prefHeight="24.0" prefWidth="241.0" text="--">
<font>
<Font name="Segoe UI" size="19.0" />
</font>
</Label>
</children>
</Pane>
</children>
</Pane>
</children>
</AnchorPane>
FXMLDocument.FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import com.jfoenix.controls.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="437.0" prefWidth="725.0" style="-fx-background-color: #f1f1f1;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="agenda.FXMLDocumentController">
<children>
<ImageView fitHeight="437.0" fitWidth="418.0" opacity="0.39" pickOnBounds="true">
<image>
<Image url="#../img/grafismo.jpg" />
</image>
</ImageView>
<Pane layoutX="418.0" prefHeight="437.0" prefWidth="307.0" style="-fx-background-color: #ffffff;">
<children>
<JFXTextField fx:id="txtPesquisar" focusColor="WHITE" layoutX="64.0" layoutY="14.0" prefHeight="39.0" prefWidth="224.0" promptText="Pesquisar" unFocusColor="WHITE">
<font>
<Font size="18.0" />
</font>
</JFXTextField>
<Separator layoutX="24.0" layoutY="36.0" prefHeight="39.0" prefWidth="265.0" />
<JFXButton fx:id="btnPesquisar" layoutX="24.0" layoutY="16.0" onAction="#btnPesquisarClique" prefHeight="33.0" prefWidth="34.0" text="Q" />
<JFXListView fx:id="listView" layoutX="24.0" layoutY="61.0" prefHeight="358.0" prefWidth="278.0" stylesheets="#style.css" />
<JFXButton fx:id="FAB" buttonType="RAISED" layoutX="228.0" layoutY="360.0" onAction="#FABClique" prefHeight="54.0" prefWidth="54.0" ripplerFill="#a8a8a8" style="-fx-background-radius: 50 50 50 50; -fx-background-color: #16a085;" text="+" textFill="WHITE">
<font>
<Font name="System Bold" size="24.0" />
</font>
</JFXButton>
</children>
</Pane>
<AnchorPane fx:id="paneFundo" prefHeight="437.0" prefWidth="418.0" />
</children>
</AnchorPane>
And the error:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at agenda.PaneInfoPA.atualizarDados(PaneInfoPA.java:48)
at agenda.FXMLDocumentController.itemListaSelecionado(FXMLDocumentController.java:54)
at agenda.FXMLDocumentController.lambda$0(FXMLDocumentController.java:82)
at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102)
at javafx.scene.control.MultipleSelectionModelBase.lambda$new$34(MultipleSelectionModelBase.java:67)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:72)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:147)
at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68)
at javafx.scene.control.MultipleSelectionModelBase.select(MultipleSelectionModelBase.java:404)
at javafx.scene.control.MultipleSelectionModelBase.clearAndSelect(MultipleSelectionModelBase.java:356)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel.clearAndSelect(ListView.java:1403)
at com.sun.javafx.scene.control.behavior.CellBehaviorBase.simpleSelect(CellBehaviorBase.java:256)
at com.sun.javafx.scene.control.behavior.CellBehaviorBase.doSelect(CellBehaviorBase.java:220)
at com.sun.javafx.scene.control.behavior.CellBehaviorBase.mousePressed(CellBehaviorBase.java:150)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:95)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

Related

JavaFX pass arguments

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

Couldn't add listener to text field javafx

I am trying to add listener to the textfield in the controler but cudnt do it . i coudnt find any options of textfield in the controler while using the fx:id given to that specific text field.
sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.effect.Reflection?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="294.0" prefWidth="883.0" style="-fx-background-color: #000000;" stylesheets="#style.css" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controler">
<children>
<Label layoutX="28.0" layoutY="55.0" text="Enter Text : " AnchorPane.leftAnchor="28.0">
<font>
<Font size="15.0" />
</font>
</Label>
<TextField fx:id="msg_tb" alignment="CENTER" layoutX="117.0" layoutY="52.0" prefHeight="25.0" prefWidth="342.0" style="-fx-background-radius: 10;" stylesheets="#style.css" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="424.0" />
<TextField fx:id="n_msg_tb" alignment="CENTER" layoutX="117.0" layoutY="93.0" prefHeight="25.0" prefWidth="342.0" style="-fx-background-radius: 10;" stylesheets="#style.css" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="424.0" />
<Button fx:id="reset_b" alignment="CENTER" layoutX="602.0" layoutY="171.0" mnemonicParsing="false" onAction="#reset" style="-fx-text-fill: #FFFFFF; -fx-background-radius: 20;" stylesheets="#style.css" text="RESET" AnchorPane.rightAnchor="161.0">
<font>
<Font name="Calibri Bold" size="31.0" />
</font>
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
<VBox layoutX="495.0" layoutY="31.0" prefHeight="169.0" prefWidth="167.0" spacing="3.0" stylesheets="#style.css" AnchorPane.rightAnchor="221.0">
<children>
<RadioButton fx:id="er" mnemonicParsing="false" onAction="#er_action" prefHeight="17.0" prefWidth="92.0" stylesheets="#application.css" text="ENCRIPTION" textFill="#797979">
<toggleGroup>
<ToggleGroup fx:id="group1" />
</toggleGroup>
</RadioButton>
<AnchorPane fx:id="ebox" prefHeight="150.0" prefWidth="167.0">
<children>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="7.0" layoutY="2.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="NUMBER LETTER">
<graphic>
<Button minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_nl" prefHeight="15.0" prefWidth="15.0" text="*">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="60.0" layoutX="8.0" layoutY="27.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="AT-BASH">
<graphic>
<Button graphicTextGap="0.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_at" prefHeight="15.0" prefWidth="15.0" text="Button">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="8.0" layoutY="52.0" prefHeight="25.0" prefWidth="105.0" stylesheets="#style.css" text="CEASER">
<graphic>
<TextField fx:id="e_key_tb" onAction="#e_c_key_tb" prefHeight="25.0" prefWidth="40.0" promptText="KEY" style="-fx-background-radius: 10;" stylesheets="#style.css" />
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Button alignment="CENTER" disable="true" layoutX="110.0" layoutY="67.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_c" prefHeight="25.0" prefWidth="40.0" style="-fx-background-radius: 10;" stylesheets="#application.css" text="CEASER" textAlignment="CENTER">
<font>
<Font name="System Italic" size="8.0" />
</font>
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</children>
</AnchorPane>
</children>
</VBox>
<VBox layoutX="662.0" layoutY="31.0" prefHeight="169.0" prefWidth="167.0" spacing="3.0" stylesheets="#style.css" AnchorPane.rightAnchor="54.0">
<children>
<RadioButton fx:id="dr" mnemonicParsing="false" onAction="#dr_action" prefHeight="17.0" prefWidth="98.0" stylesheets="#application.css" text="DECRIPTION" textFill="#797979" toggleGroup="$group1" />
<AnchorPane fx:id="dbox" prefHeight="150.0" prefWidth="167.0" visible="false">
<children>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="7.0" layoutY="2.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="NUMBER LETTER">
<graphic>
<Button minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="15.0" prefWidth="15.0" text="*">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="60.0" layoutX="8.0" layoutY="27.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="AT-BASH">
<graphic>
<Button graphicTextGap="0.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="15.0" prefWidth="15.0" text="Button">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="8.0" layoutY="52.0" prefHeight="25.0" prefWidth="105.0" stylesheets="#style.css" text="CEASER">
<graphic>
<TextField fx:id="d_key_tb" onAction="#d_c_key_tb" prefHeight="25.0" prefWidth="40.0" promptText="KEY" style="-fx-background-radius: 10;" stylesheets="#style.css" />
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Button disable="true" layoutX="110.0" layoutY="67.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#d_c" prefHeight="25.0" prefWidth="40.0" style="-fx-background-radius: 10;" stylesheets="#application.css" text="CEASER" textAlignment="CENTER">
<font>
<Font name="System Italic" size="8.0" />
</font>
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</children>
</AnchorPane>
</children>
</VBox>
</children>
</fx:root>
controler.java
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.AnchorPane;
public class controler implements Initializable {
#FXML
private TextField msg_tb;
#FXML
private TextField n_msg_tb;
#FXML
private Button reset_b;
#FXML
private RadioButton er;
#FXML
private ToggleGroup group1;
#FXML
private RadioButton dr;
#FXML
private AnchorPane ebox;
#FXML
private AnchorPane dbox;
#FXML
public TextField e_key_tb;
#FXML
private TextField d_key_tb;
#FXML
void d_c(ActionEvent event) {
}
#FXML
void d_c_key_tb(ActionEvent event) {
}
#FXML
void dr_action(ActionEvent event) {
dbox.setVisible(true);
dbox.setDisable(false);
ebox.setVisible(false);
ebox.setDisable(true);
}
#FXML
void e_at(ActionEvent event) {
}
#FXML
void e_c(ActionEvent event) {
}
#FXML
void e_c_key_tb(ActionEvent event) {
}
#FXML
void e_nl(ActionEvent event) {
}
#FXML
void er_action(ActionEvent event) {
ebox.setVisible(true);
ebox.setDisable(false);
dbox.setVisible(false);
dbox.setDisable(true);
}
#FXML
void reset(ActionEvent event) {
}
#Override
public void initialize(URL location, ResourceBundle resources) {
ArrayList<morse> mkey = new ArrayList<>();
try {
morse.load(mkey);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public TextField getMsg_tb() {
return msg_tb;
}
public void setMsg_tb(TextField msg_tb) {
this.msg_tb = msg_tb;
}
public TextField getN_msg_tb() {
return n_msg_tb;
}
public void setN_msg_tb(TextField n_msg_tb) {
this.n_msg_tb = n_msg_tb;
}
public Button getReset_b() {
return reset_b;
}
public void setReset_b(Button reset_b) {
this.reset_b = reset_b;
}
public RadioButton getEr() {
return er;
}
public void setEr(RadioButton er) {
this.er = er;
}
public ToggleGroup getGroup1() {
return group1;
}
public void setGroup1(ToggleGroup group1) {
this.group1 = group1;
}
public RadioButton getDr() {
return dr;
}
public void setDr(RadioButton dr) {
this.dr = dr;
}
public AnchorPane getEbox() {
return ebox;
}
public void setEbox(AnchorPane ebox) {
this.ebox = ebox;
}
public AnchorPane getDbox() {
return dbox;
}
public void setDbox(AnchorPane dbox) {
this.dbox = dbox;
}
public TextField getE_key_tb() {
return e_key_tb;
}
public void setE_key_tb(TextField e_key_tb) {
this.e_key_tb = e_key_tb;
}
public TextField getD_key_tb() {
return d_key_tb;
}
public void setD_key_tb(TextField d_key_tb) {
this.d_key_tb = d_key_tb;
}
e_key_tb.textProperty().addListener((obs, oldText, newText) -> {
System.out.println("Text changed from "+ oldText +" to "+newText);
});
}
}
when I am trying to add the listener at the end it is not working. I can't get any options for textfield when I do e_key_tb. and ctrl+space where it is supposed to give a drop down box with a bunch of suggestions ... I used the scene-builder to provide id and copied the controller skeliton from the scene-builder ... later when I'm trying to use the textfield it made me create getters and setters for all the textfields can you explain me y it s happening and I never used listeners before.
Here is a short demonstration of adding a listener to a TextField. This can also serve as an example for mcve for the issue:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.TextField?>
<HBox prefHeight="75.0" prefWidth="150.0" alignment="CENTER"
xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tests.Controler">
<children>
<TextField fx:id="msg_tb" prefHeight="25.0" prefWidth="100.0" style="-fx-background-radius: 10;" />
</children>
</HBox>
The controller :
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
public class Controler implements Initializable {
#FXML
private TextField msg_tb;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
msg_tb.textProperty().addListener((obs, oldText, newText) -> {
System.out.println("Text changed from "+ oldText +" to "+newText);
});
}
}
Test it:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class FxmlMain extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Pane root = FXMLLoader.load(getClass().getResource("xml/FxmlMain.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) { launch(args);}
}

javafx fxml LoadException

I am quite new at JavaFx. I am trying to build a simple calculator by following a tutorial . I followed the tutorial step by step . When I run the project , it shows javafx fxml LoadException. I watched some solution relating to this but still I can not fix it. Please help me to fix this error.(Sorry for a long post)
my program files are below
MainController.java
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class MainController {
#FXML
private Label result; // label variable shows output above the buttons, check this
private long number1 = 0;
private String operator = "";
private boolean start = true;
private Model model = new Model();
#FXML
public void processNumbers(ActionEvent event) {
if (start) {
result.setText(""); // set the label(output) screen as blank first
start = false;
}
String value = ((Button) event.getSource()).getText(); // take number 1-9 and convert it into String, import the
// button class otherwise will shows error
result.setText(result.getText() + value);
}
#FXML
public void processOperators(ActionEvent event) {
String value = ((Button) event.getSource()).getText();`enter code here`
if (!value.equals("=")) {
if (!operator.isEmpty()) {
return;
}
operator = value;
number1 = Long.parseLong(result.getText());
result.setText("");
} else {
if (operator.isEmpty())
return;
long number2 = Long.parseLong(result.getText());
float output = model.calculate(number2, number2, operator);
result.setText(String.valueOf(output));
start = true;
}
}
}
Model.java
package application;
public class Model { //for some action event
public float calculate(long number1,long number2,String operator) {
switch(operator) {
case "+":
return number1+number2;
case "-":
return number1-number2;
case "*":
return number1*number2;
case "/":
if(number2==0) return 0;
return number1+number2;
default:
return 0;
}//switch case
}
}
Main.java
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.control.*;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = (Parent) FXMLLoader.load(getClass().getResource("/application/CalculatorFxmlFile.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
CalculatorFxmlFile
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
<children>
<StackPane prefHeight="50.0" prefWidth="200.0">
<children>
<Label fx:id="result" prefHeight="17.0" prefWidth="327.0" text="Label">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
</children></StackPane>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="7">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="8">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="9">
<font>
<Font size="18.0" />
</font>
</Button>
<Button fx:id="result" mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="/">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="4">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="5">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="6">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="*">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="1">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="2">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="3">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="-">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="110.0" text="0">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="=">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="+">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
</children>
</VBox>
Exceptions generated
javafx.fxml.LoadException:
/C:/AllPrograms/Java/eclipse1/CalculatorJavaFx/bin/application/CalculatorFxmlFile.fxml:37
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:15)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Can not set javafx.scene.control.Label field application.MainController.result to javafx.scene.control.Button
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
Here is your error (in your fxml file):
<Button fx:id="result" mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="/">
<font>
<Font size="18.0" />
</font>
</Button>
This button id is "result" which is also the id of a label. You should either remove this id attribute (I think you missplaced it there) or change it to the one suggested by the tutorial.
UPDATE
This operation is division but you are adding the numbers number1 and number2
case "/":
if(number2==0) return 0;
return number1+number2;
so you should perform a division not addition
case "/":
if(number2==0) return 0;
return number1/number2;
UPDATE 2
Another error I spotted is also here:
float output = model.calculate(number2, number2, operator);
You missed the number1 variable in the calculate method:
float output = model.calculate(number1, number2, operator);

Why is the Capitalization delayed in this JavaFx App when using change listener?

I have this simple app on JavaFx that creates lazy instanziators for javafx beans, the app is entirely gui, it only has an fxml and main class
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.SuperLazyfxController">
<children>
<StackPane layoutX="3.0" prefHeight="400.0" prefWidth="594.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#0f5694" height="392.0" stroke="BLACK" strokeType="INSIDE" width="594.0" />
<AnchorPane prefHeight="344.0" prefWidth="594.0">
<children>
<VBox alignment="CENTER" layoutX="38.0" layoutY="59.0" prefHeight="144.0" prefWidth="459.0" spacing="10.0" AnchorPane.bottomAnchor="134.0" AnchorPane.leftAnchor="38.0" AnchorPane.rightAnchor="67.0" AnchorPane.topAnchor="59.0">
<children>
<HBox prefHeight="29.0" prefWidth="537.0">
<children>
<Label alignment="CENTER_RIGHT" prefHeight="65.0" prefWidth="262.0" text="Accesibilidad Property :" textFill="#ae9c3e">
<font>
<Font name="Ebrima Bold" size="18.0" />
</font>
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Label>
<TextField fx:id="accesib" prefHeight="72.0" prefWidth="277.0" />
</children>
</HBox>
<HBox prefHeight="29.0" prefWidth="537.0">
<children>
<Label alignment="CENTER_RIGHT" prefHeight="65.0" prefWidth="262.0" text="TipoProperty" textFill="#ae9c3e">
<font>
<Font name="Ebrima Bold" size="18.0" />
</font>
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Label>
<TextField fx:id="Tipo" prefHeight="72.0" prefWidth="277.0" />
</children>
</HBox>
<HBox prefHeight="29.0" prefWidth="537.0">
<children>
<Label alignment="CENTER_RIGHT" contentDisplay="RIGHT" prefHeight="29.0" prefWidth="261.0" text="Nombre Property :" textFill="#ae9c3e">
<font>
<Font name="Ebrima Bold" size="18.0" />
</font>
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Label>
<TextField fx:id="nombre" onKeyReleased="#mayusculas" prefHeight="72.0" prefWidth="277.0" />
</children>
</HBox>
<HBox prefHeight="29.0" prefWidth="537.0">
<children>
<Label alignment="CENTER_RIGHT" contentDisplay="RIGHT" prefHeight="29.0" prefWidth="261.0" text="Shadowfield type" textFill="#ae9c3e">
<font>
<Font name="Ebrima Bold" size="18.0" />
</font>
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Label>
<TextField fx:id="tiposhadow" prefHeight="72.0" prefWidth="277.0" />
</children>
</HBox>
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#Clean" text="Clean" textFill="#907c39">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Button>
</children>
</VBox>
<TextArea fx:id="area" layoutX="15.0" layoutY="267.0" prefHeight="118.0" prefWidth="563.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="16.0" AnchorPane.topAnchor="267.0" />
<Label alignment="CENTER" layoutX="139.0" prefHeight="62.0" prefWidth="321.0" text="Super-Lazy Insta JavaFX" textFill="RED" AnchorPane.bottomAnchor="338.0" AnchorPane.leftAnchor="139.0" AnchorPane.rightAnchor="134.0" AnchorPane.topAnchor="0.0">
<font>
<Font name="System Bold" size="25.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</StackPane>
</children>
</AnchorPane>
Here the main class:
package app;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class App extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("SuperLazyfx.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Lazy-instanziatior");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
and here is the controller class
package app;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
public class SuperLazyfxController implements Initializable {
#FXML
private TextField Tipo;
#FXML
private TextField nombre;
#FXML
private TextField tiposhadow;
#FXML
private TextField accesib;
#FXML
private TextArea area;
private StringBinding sbind;
private StringProperty nombreMayus = new SimpleStringProperty("Nombrevar");
private StringProperty nombreMin = new SimpleStringProperty("");
#Override
public void initialize(URL url, ResourceBundle rb) {
sbind = new StringBinding() {
{
super.bind(Tipo.textProperty(), nombre.textProperty(), tiposhadow.textProperty(), accesib.textProperty());
}
#Override
protected String computeValue() {
return accesib.textProperty().get() + " " + Tipo.textProperty().get() + " " + nombre.textProperty().get() + ";\n"
+ accesib.textProperty().get() + " " + tiposhadow.textProperty().get() + " _" + nombre.textProperty().get() + ";\n\n"
+ "public " + tiposhadow.textProperty().get() + " get" + nombreMayus.get() + nombreMin.get()+"(){"
+ "\n\t return ("+nombre.textProperty().get()+" ==null)? _"+nombre.textProperty().get()+": "+nombre.textProperty().get()+".get();\n"
+"}\n\n"
+ "public void set"+ nombreMayus.get() + nombreMin.get()+"("+tiposhadow.textProperty().get()+" "+nombre.textProperty().get()+"){"
+ "\t\nif(this."+nombre.textProperty().get()+"==null){\n"
+ "\t_"+nombre.textProperty().get()+"="+nombre.textProperty().get()+";\n"
+ "\t} else{\n"
+ "\tthis."+nombre.textProperty().get()+".set("+nombre.textProperty().get()+");\n"
+ "\t}\n"
+ "}\n\n"
+ "public "+ Tipo.textProperty().get()+" "+nombre.textProperty().get()+"Property(){\n"
+ "\treturn ("+nombre.textProperty().get()+"== null)? "+nombre.textProperty().get()+"= new Simple"+Tipo.textProperty().get()+"(this,\""+nombre.textProperty().get()+"\", _"+nombre.textProperty().get()+"): "+nombre.textProperty().get()+";\n"
+ "}"
;
}
};
area.textProperty().bind(sbind);
}
#FXML
private void mayusculas(KeyEvent event) {
nombre.textProperty().addListener((ov, oldV, newV) -> {
if (!(nombre.textProperty().get().isEmpty())) {
nombreMayus.set(newV.substring(0, 1).toUpperCase());
} else {
nombreMayus.set("Nombrevar");
}
});
nombre.textProperty().addListener((ov, oldV, newV) -> {
if (!(nombre.textProperty().get().isEmpty())) {
nombreMin.set(newV.substring(1));
} else {
nombreMin.set("");
}
});
}
#FXML
private void Clean(ActionEvent event) {
Tipo.textProperty().set("");
nombre.textProperty().set("");
tiposhadow.textProperty().set("");
accesib.textProperty().set("");
}
}
The problem falls here:
#FXML
private void mayusculas(KeyEvent event) {
nombre.textProperty().addListener((ov, oldV, newV) -> {
if (!(nombre.textProperty().get().isEmpty())) {
nombreMayus.set(newV.substring(0, 1).toUpperCase());
} else {
nombreMayus.set("Nombrevar");
}
});
nombre.textProperty().addListener((ov, oldV, newV) -> {
if (!(nombre.textProperty().get().isEmpty())) {
nombreMin.set(newV.substring(1));
} else {
nombreMin.set("");
}
});
}
And here:
+ "public void set"+ nombreMayus.get() + nombreMin.get()+"("+tiposhadow.textProperty().get()+" "+nombre.textProperty().get()+"){"
the nombreMayus.get() shows, when the first letter is typed "Nombrevar" on the Text Area while when the second one is typed it shows the first letter you see!!! It is delayed
It is not correct to add change listener in onKeyReleased() event. This way you are adding a brand new listener every single time the user keys something on the keyboard.
You can probably do this:
nombreMayus.bind(() -> nombre.getText().substring(0, 1).toUpperCase(), nombre.textProperty());
nombreMin.bind(() -> nombre.getText().substring(1), nombre.textProperty());

getting value from another package

I wanna get a value from "application" package and use it in "packet" package, but my way doesnt work. I want lblCal in "packet" package to have the same value as loppkcal or lblKcal has in "application" package.
Im sorry if my code looks like shit.
i also mention that arvutaNuppVajutus is the button On Action.
I added comments to code, what i mean ( "application" package has the comment in the bottom).
package packet;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import application.MainControll;
public class Paevikcontroll {
#FXML
private HBox hbboxKast;
#FXML
private TextField lisaToit;
#FXML
private TextField lisaValk;
#FXML
private TextField lisaSysi;
#FXML
private TextField lisaRasv;
#FXML
private ComboBox cbToiduaine;
#FXML
private TextField txtKogus;
#FXML
private Label lblCal;
#FXML
private Label lblProt;
#FXML
private Label lblCarb;
#FXML
private Label lblFat;
private void initialize() {
MainControll nr = new MainControll();
lblCal.setText(nr.arvutaNuppVajutus.loppkcal); //Want same value for this as lblKcal or loppkcal has in "application" package.
}
}
And here is the "application" package i wanna get the value from.
package application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class MainControll {
ObservableList<String> Sugu = FXCollections.observableArrayList("Mees", "Naine");
ObservableList<String> Aktiivsus = FXCollections.observableArrayList("Puudulik", "Madal", "Keskmine", "Kõrge");
ObservableList<String> Goal = FXCollections.observableArrayList("Kaalu langetamine", "Kaalu säilitamine",
"Kaalu tõstmine");
#FXML
private TextField txtPikkus;
#FXML
private TextField txtKaal;
#FXML
private TextField txtVanus;
#FXML
private ComboBox cbAktiivsus;
#FXML
private ComboBox cbSugu;
#FXML
private ComboBox cbValik;
#FXML
public static Label lblKcal;
#FXML
public Label lblValk;
#FXML
public Label lblSysi;
#FXML
public Label lblRasv;
#FXML
private Label lblVigaPikk;
#FXML
private Label lblVigaKaal;
#FXML
private Label lblVigaVanus;
#FXML
private Label lblVigaAktiivsus;
#FXML
private Label lblVigaSugu;
#FXML
private Label lblVigaGoal;
#FXML
private void initialize() {
cbSugu.setItems(Sugu);
cbAktiivsus.setItems(Aktiivsus);
cbValik.setItems(Goal);
}
public void arvutaNuppVajutus() {
double pikk = 0;
double kaal = 0;
double vanus = 0;
try {
pikk = Double.parseDouble(txtPikkus.getText());
} catch (NumberFormatException e) {
lblVigaPikk.setText("Lisa pikkus numbrites!");
}
try {
kaal = Double.parseDouble(txtKaal.getText());
} catch (NumberFormatException e) {
lblVigaKaal.setText("Lisa kaal numbrites!");
}
try {
vanus = Double.parseDouble(txtVanus.getText());
} catch (NumberFormatException e) {
lblVigaVanus.setText("Lisa vanus numbrites!");
}
double esikcal = 0;
double keskkcal = 0;
int loppkcal = 0;
int sysivesik;
try {
if (cbSugu.getSelectionModel().getSelectedItem().equals("Mees")) {
esikcal = 10 * kaal + 6.25 * pikk - 5 * vanus + 5;
}
if (cbSugu.getSelectionModel().getSelectedItem().equals("Naine")) {
esikcal = 10 * kaal + 6.25 * pikk - 5 * vanus - 161;
}
} catch (NullPointerException e) {
lblVigaSugu.setText("Unustasid soo lisamata!");
}
try {
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Puudulik")) {
keskkcal = 1.0 * esikcal;
break;
}
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Madal")) {
keskkcal = 1.4 * esikcal;
break;
}
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Keskmine")) {
keskkcal = 1.6 * esikcal;
break;
}
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Kõrge")) {
keskkcal = 1.8 * esikcal;
break;
}
} catch (NullPointerException e) {
lblVigaAktiivsus.setText("Unustasid aktiivsuse valimata!");
}
try {
if (cbValik.getSelectionModel().getSelectedItem().equals("Kaalu langetamine")) {
loppkcal = (int) (keskkcal - (keskkcal * 0.1));
}
if (cbValik.getSelectionModel().getSelectedItem().equals("Kaalu säilitamine")) {
loppkcal = (int) keskkcal;
}
if (cbValik.getSelectionModel().getSelectedItem().equals("Kaalu tõstmine")) {
loppkcal = (int) (keskkcal + (keskkcal * 0.1));
}
} catch (NullPointerException e) {
lblVigaGoal.setText("Vali eesmärk!");
}
lblKcal.setText((Double.toString(loppkcal)) + " kcal"); //Wanna do the same as i have done here, in the "packet" package to lblCal.
lblValk.setText((Double.toString(kaal * 2)) + " g");
lblRasv.setText((Double.toString(kaal)) + " g");
sysivesik = (int) (loppkcal - (kaal * 8) - (kaal * 9)) / 4;
lblSysi.setText((Double.toString(sysivesik)) + " g");
}
public void pressButton(ActionEvent event) throws Exception {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
Parent root1 = (Parent) fxmlLoader.load(getClass().getResource("/packet/PaevikInterface.fxml"));
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Also here are FXML codes, if those are any help.
the FXML code thats in "application" package
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainControll">
<children>
<Button fx:id="btnArvuta" layoutX="305.0" layoutY="281.0" mnemonicParsing="false" onAction="#arvutaNuppVajutus" text="Arvuta" textFill="#0a0a0a">
<font>
<Font size="18.0" />
</font>
</Button>
<TextField fx:id="txtPikkus" layoutX="25.0" layoutY="36.0" promptText="Sisesta pikkus">
<font>
<Font size="18.0" />
</font>
</TextField>
<TextField fx:id="txtKaal" layoutX="25.0" layoutY="92.0" promptText="Sisesta kaal">
<font>
<Font size="18.0" />
</font>
</TextField>
<Label layoutX="35.0" layoutY="1.0" text="Arvuta päevane kaloraazh">
<font>
<Font size="18.0" />
</font>
</Label>
<ComboBox fx:id="cbValik" layoutX="23.0" layoutY="283.0" prefWidth="150.0" promptText="Eesmärk" />
<Label layoutX="27.0" layoutY="325.0" text="Päevane soovituslik kcal ja makrotoitained on:">
<font>
<Font size="18.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="352.0" text="Kcal:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="377.0" text="Valgud:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="403.0" text="Süsivesikud:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="427.0" text="Rasvad:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblKcal" layoutX="137.0" layoutY="355.0" text="0 kcal">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblValk" layoutX="137.0" layoutY="377.0" text="0 g">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblSysi" layoutX="137.0" layoutY="403.0" text="0 g">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblRasv" layoutX="137.0" layoutY="427.0" text="0 g">
<font>
<Font size="19.0" />
</font>
</Label>
<ComboBox fx:id="cbAktiivsus" layoutX="23.0" layoutY="192.0" prefWidth="150.0" promptText="Vali aktiivsus" />
<ComboBox fx:id="cbSugu" layoutX="23.0" layoutY="236.0" prefWidth="150.0" promptText="Sugu" />
<Button fx:id="btnPaevik" layoutX="23.0" layoutY="489.0" mnemonicParsing="false" onAction="#pressButton" prefHeight="56.0" prefWidth="162.0" text="Toitumispäevik">
<font>
<Font size="20.0" />
</font>
</Button>
<TextField fx:id="txtVanus" layoutX="27.0" layoutY="142.0" prefHeight="37.0" prefWidth="64.0" promptText="Vanus">
<font>
<Font size="16.0" />
</font>
</TextField>
<Label fx:id="lblVigaPikk" layoutX="254.0" layoutY="37.0" prefHeight="37.0" prefWidth="142.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaKaal" layoutX="254.0" layoutY="93.0" prefHeight="37.0" prefWidth="142.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaVanus" layoutX="102.0" layoutY="142.0" prefHeight="37.0" prefWidth="217.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaAktiivsus" layoutX="185.0" layoutY="186.0" prefHeight="37.0" prefWidth="205.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaSugu" layoutX="183.0" layoutY="233.0" prefHeight="37.0" prefWidth="205.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaGoal" layoutX="183.0" layoutY="277.0" prefHeight="37.0" prefWidth="120.0" text="-
" textFill="RED" />
</children>
</AnchorPane>
and the FXML code thats in "packet" package
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox fx:id="hboxKAst" layoutX="38.0" layoutY="37.0" prefHeight="100.0" prefWidth="547.0">
<children>
<TextField fx:id="lisaToit" prefHeight="25.0" prefWidth="192.0" promptText="Toiduaine" />
<TextField fx:id="lisaValk" prefHeight="25.0" prefWidth="56.0" promptText="Valgud" />
<TextField fx:id="lisaSysi" prefHeight="25.0" prefWidth="90.0" promptText="Süsivesikud" />
<TextField fx:id="lisaRasv" prefHeight="25.0" prefWidth="54.0" promptText="Rasvad" />
<Button fx:id="lisaNupp" mnemonicParsing="false" prefHeight="25.0" prefWidth="131.0" text="Lisa andmebaasi" />
</children>
</HBox>
<ComboBox fx:id="cbToiduaine" layoutX="38.0" layoutY="169.0" prefWidth="150.0" promptText="Vali toiduaine" />
<TextField fx:id="txtKogus" layoutX="204.0" layoutY="169.0" prefHeight="25.0" prefWidth="112.0" promptText="Kogus grammides" />
<TableView fx:id="tbTabel" layoutX="38.0" layoutY="227.0" prefHeight="333.0" prefWidth="555.0">
<columns>
<TableColumn fx:id="tbToit" prefWidth="188.0" text="Toiduaine nimetus" />
<TableColumn fx:id="tbValk" prefWidth="85.0" text="Valgud" />
<TableColumn fx:id="tbSysi" prefWidth="81.0" text="Süsivesikud" />
<TableColumn fx:id="tbRasv" prefWidth="92.0" text="Rasvad" />
<TableColumn fx:id="tbKcal" prefWidth="104.0" text="Kalorid" />
</columns>
</TableView>
<Button fx:id="lisaMenyy" layoutX="339.0" layoutY="169.0" mnemonicParsing="false" text="Lisa menüüsse" />
<Button layoutX="636.0" layoutY="37.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="150.0" text="Toiduainete andmebaas" />
<Label layoutX="608.0" layoutY="238.0" prefHeight="45.0" prefWidth="176.0" text="Sinule vajalik kogus kaloreid
ja makrotoitaineid:
">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="292.0" text="Kcal:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="324.0" text="Valgud:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="352.0" text="Süsivesikud:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="385.0" text="Rasvad:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label fx:id="lblCal" layoutX="658.0" layoutY="294.0" text="0 kcal" />
<Label fx:id="lblProt" layoutX="672.0" layoutY="326.0" text="0 g" />
<Label fx:id="lblCarb" layoutX="697.0" layoutY="354.0" text="0 g" />
<Label fx:id="lblFat" layoutX="672.0" layoutY="387.0" text="0 g" />
</children>
</AnchorPane>
You could change this:
lblCal.setText(nr.arvutaNuppVajutus.loppkcal); //Want same value for this as lblKcal or loppkcal has in "application" package.
to
lblCal.setText(nr.arvutaNuppVajutu());
and change arvutaNuppVajutu() to
public string arvutaNuppVajutu() {
..
return "" + lblKcal;
}

Categories