Last active
December 20, 2015 11:09
-
-
Save komax/6121369 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm | |
require 'jrubyfx' | |
require 'open-uri' | |
class FirstLineURLTask < Java::javafx.concurrent.Task | |
def initalize(url) | |
@url = url | |
end | |
def call | |
first_line = open(@url) do |f| | |
f.readline | |
end | |
return first_line | |
end | |
end | |
class FirstLineService < Java::javafx.concurrent.Service | |
include JRubyFX | |
property_accessor :url | |
def initialize | |
super() | |
@url = SimpleStringProperty.new | |
end | |
protected | |
def createTask | |
return FirstLineURLTask.new(@url) | |
end | |
end | |
class FirstLineServiceApp < JRubyFX::Application | |
def start(stage) | |
service = FirstLineService.new | |
service.url = "http://google.com" | |
service.on_succeeded do |t| | |
puts "done" | |
end | |
service.start() | |
with(stage, | |
title: "Service Demo: Retrieves first line of URL in background", width: 300, height: 150) do | |
layout_scene do | |
label(id: "result", text: "working") | |
end | |
end | |
stage.show | |
end | |
end | |
FirstLineServiceApp.launch | |
# I'll get | |
=begin | |
% jruby url_service_demo.rb | |
Exception running Application: | |
#<ArgumentError: wrong number of arguments (1 for 0)> | |
url_service_demo.rb:39:in `start' | |
/home/max/Programmierung/gsoc/jruby/lib/ruby/gems/shared/gems/jrubyfx-1.0.0-java/lib/jrubyfx/java_fx_impl.rb:120:in `launch_app_after_platform' | |
org/jruby/gen/InterfaceImpl299080017.gen:13:in `run' | |
=end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment