JRubyFXでコンストラクタに引数を渡しつつControllerを切り替えるには、javafx.stage.Stage#fxml
メソッドを使います。
以下のようなmove
メソッドを定義したApplicationController
を作成し、各コントローラはそれを継承する様にすれば便利でしょう。
application_controller.rb
class ApplicationController
include JRubyFX::Controller
def move klass, *args
@stage.fxml klass, initialize: args
@stage.show
end
end
foo_controller.rb
class FooController < ApplicationController
def initialize arg
puts "I got `#{arg}` as a constructor argument!"
end
def click_button
move BarController, "Hello, Bar!"
end
end
bar_controller.rb
class BarController < ApplicationController
def initialize arg
puts "I got `#{arg}` as a constructor argument!"
end
def click_button
move FooController, "Hello, Foo!"
end
end