JavaFX控制器類無(wú)法正常工作我真的很難理解JavaFX控制器,我的目標(biāo)是寫(xiě)一個(gè)TextArea來(lái)充當(dāng)日志。我的代碼如下,但我希望能夠在需要時(shí)從另一個(gè)類中更改值ETC。我試圖創(chuàng)建一個(gè)擴(kuò)展Initializable的控制器類,但我不能讓它工作。有人可以引導(dǎo)我朝正確的方向前進(jìn)嗎?我想將底部的@FXML代碼移動(dòng)到另一個(gè)類并更新Scene。package application;import javafx.event.ActionEvent;import javafx.scene.control.Label;import javafx.scene.control.TextArea;import java.io.IOException;import javafx.application.Application;import javafx.fxml.FXML;import javafx.fxml.FXMLLoader;import javafx.stage.Stage;import javafx.scene.Parent;import javafx.scene.Scene;public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("Root.fxml"));
Scene scene = new Scene(root,504,325);
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);
}
public Thread thread = new Thread(new webimporter());
@FXML
public Label runningLabel;
@FXML
public TextArea txtArea;
@FXML
void runClick(ActionEvent event) throws IOException{
changeLabelValue("Importer running...");
thread.start();
}
@FXML
protected void stopClick(ActionEvent event){
changeLabelValue("Importer stopped...");
thread.interrupt();
}
@FXML
void changeLabelValue(String newText){
runningLabel.setText(newText);
}
void changeTextAreaValue(String newText1){
txtArea.setText(newText1);
}}
JavaFX控制器類無(wú)法正常工作
炎炎設(shè)計(jì)
2019-08-23 09:55:56