I have tried following the solution from here but without success: JavaFX Change label text from another class with controller
I am not sure if they want the same as I do.
So basically what I have is: FXMLDocumentController.java
, FXMLDocument.xml, Operations.java
, and Main.java
. (I have some other classes that make the Arduino connection)
This is the start method that I have in my Main.java
:
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("This is the title");
primaryStage.setScene(scene);
primaryStage.show();
}
EDIT: Here's my Operations.java:
public class Operations {
private String mensagem, hora, dados;
private String [] msgSeparada, dadosSeparados;
private int origem, destino, tipoMensagem, comprimento;
private int [] estadoDosSensores;
public FiltrarMensagem(String mensagem) {
//remove o primeiro e ultimo carater
mensagem = mensagem.substring(1, mensagem.length()-2);
this.mensagem = mensagem;
System.out.printf("Mensagem Recebida: %s\n", mensagem);
msgSeparada = this.mensagem.split(";");
destino = Integer.valueOf(msgSeparada[0]);
origem = Integer.valueOf(msgSeparada[1]);
hora = msgSeparada[2];
tipoMensagem = Integer.valueOf(msgSeparada[3]);
comprimento = Integer.valueOf(msgSeparada[4]);
dados = msgSeparada[5];
dadosSeparados = dados.split(",");
}
public void imprimir() {
System.out.printf("Origem: %d\n", origem);
System.out.printf("Destino: %d\n", destino);
System.out.printf("Hora: %s\n", hora);
System.out.printf("Tipo de Mensagem: %d\n", tipoMensagem);
System.out.printf("Comprimento: %d\n", comprimento);
System.out.printf("Dados: %s\n\n", dados);
if(Integer.valueOf(dadosSeparados[0]) == 1) {
//change label value here
}
}
}
To simplify, here's what my program does:
I have my controller class with 2 simple buttons that receive data from the serial port coming from an Arduino, and with the data received from the Arduino, I create an object of the class Operations so I can make the necessary changes depending on the data received from the Arduino, and what I would like to do is to change labels and all the objects available at the FXML file, but I am not able to do that. What is the simplest way to do it?
I've tried everything and with no success... So would really appreciate if someone could help me on this.