В настоящее время я изучаю JavaFX. Я создаю приложение, которое принимает файл как вход, подключается к внешнему серверу и возвращает результаты анализа в базу данных MySQL. Основная функциональность работает нормально, но я хотел бы иметь обновление JavaFX для пользователя, чтобы они знали, что они ждут подключения к серверу и т. Д. Однако при вызове метода текстовые обновления не видны до тех пор, пока метод завершил выполнение - я хотел бы, чтобы обновления происходили в реальном времени. Метод нарушитель находится ниже:JavaFX - SetText() в TextArea не выполняется до завершения программы
public void doBlast(){
//this line is not updated until completion of the program - not straight away
status.setText("Connecting to NCBI servers..NCBI" + "\n");
//Biojava API details extracted as it is not relevant
BufferedReader bufferedFileReader = null;
Scanner bufferedScanner = null;
BufferedWriter bufferedWriterXML = null;
String rid = null;
int count = 0;
try {
//this.getFasta() represents the input file
bufferedScanner
= new Scanner(new BufferedReader(new FileReader (this.getFasta())));
//this.getTempXML() is a temporary file for temporary storage of xml output from the server
bufferedWriterXML
= new BufferedWriter (new FileWriter (this.getTempXML(), true));
String line, nextline, query, xmlLine;
//Loops for a specified number of times
while (count < alignmentLimit) {
this.setSequence_id(bufferedScanner.nextLine());
//newline here
bufferedScanner.nextLine();
//this line from the file is used to search a database in the server
query = bufferedScanner.nextLine();
//this line is not updated until completion of the program - not straight away
status.setText("Connecting to NCBI servers.." + "\n");
//below service connects to server
rid = service.sendAlignmentRequest(query, props);
//results
InputStream in = service.getAlignmentResults(rid, outputProps);
//this line is not updated until completion of the program - not straight away
status.setText("Connected to NCBI." + "\n");
bufferedFileReader = new BufferedReader(new InputStreamReader(in));
xmlLine = bufferedFileReader.readLine();
while (xmlLine != null) {
bufferedWriterXML.write("\n" + xmlLine);
xmlLine = bufferedFileReader.readLine();
// have to flush here so that it prints to file;
// the file can then be deleted each loop
bufferedWriterXML.flush();
}
count++;
//this method removes specific strings
this.removeAll("<?xml", "<!DOCTYPE", this.getTempXML(), this.getXML());
//this method fills a database with the data from server
this.xml2mysql();
//file cleaning
this.eraseData(this.getTempXML());
this.eraseData(this.getXML());
bufferedScanner.nextLine();
//this line is not updated until completion of the program - not straight away
numberOfRecords.setText(Integer.toString(count));
}
}
catch (Exception anException){
anException.printStackTrace();
}
finally {
try {
bufferedWriterXML.close();
bufferedScanner.close();
bufferedFileReader.close();
}
catch (Exception anException){
System.out.println("Error: " + anException);
}
}
}
SetText() методы используют FX-FXML определяется: идентификатор переменной, и указанный выше способ находится в контроллере.
Очень ценим, если кто-нибудь может мне помочь. Я искал везде решение. Спасибо.
Предполагается использовать Platform.runLater() ;. – matt
Спасибо ... Я изучаю это сейчас. –
@James_D - Да, извините, я пропустил вопрос. Это немного отличается от обновления меток, но процесс тот же. –