LoginSignup
1
1

More than 5 years have passed since last update.

JRubyFXでコンストラクタに引数を渡しつつControllerを切り替える

Last updated at Posted at 2015-05-01

JRubyFXでコンストラクタに引数を渡しつつControllerを切り替えるには、javafx.stage.Stage#fxmlメソッドを使います。

UI via 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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1