【发布时间】:2015-11-11 22:32:24
【问题描述】:
我真的很难理解 JavaFX 控制器,我的目标是写入 TextArea 以充当日志。
我的代码如下,但我希望能够从另一个类中更改值 ETC,我可以在需要时调用它。我试图创建一个扩展 Initializable 的控制器类,但我无法让它工作。有人能引导我走向正确的方向吗?
我想将底部的@FXML 代码移动到另一个类并更新场景。
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);
}
}
【问题讨论】:
标签: java javafx scenebuilder