2
이 코드액세스 속성을 외부 클래스
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Test extends Application {
private String pageTitle;
public static void main(String args[]) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
this.setPageTitle("Hello World");
Button btn = ButtonBuilder.create()
.text("Test Button")
.onAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
// this handle should change the property if Test.pageTitle property
//this.setPageTitle("Change button");
System.out.println("Testing button action");
}
})
.build();
StackPane root = new StackPane();
root.getChildren().add(btn);
stage.setTitle(getPageTitle());
stage.setScene(new Scene(root, 400, 400));
stage.show();
}
public String getPageTitle() {
return pageTitle;
}
public void setPageTitle(String pageTitle) {
this.pageTitle = pageTitle;
}
}
내가 때마다 버튼이 응용 프로그램의 제목을 변경합니다, 클릭입니다 원하는를 참조하십시오. 이벤트 핸들러를 만들면 Text
클래스의 속성에 액세스 할 수 있습니까?
아의 현재 인스턴스를 참조해야합니다. 내가 참조. 그래서 클래스의 이름을 추가해야합니다. 고마워, 작동 해. :디 – GusDeCooL