Forum: JRuby How to use instance JRUBY_APPLET

Posted by arno boubek (boubek)
on 2012-11-16 18:08
hi

I get the following error using the JRubyApplet instance:

Exception in thread "AWT-EventQueue-1"
org.jruby.exceptions.RaiseException: (NoMethodError) undefined method
'drawString' for  Java::SunJava2D::SunGraphics2D


with the following script.rb :

include Java
JRUBY_APPLET.on_paint do |g|
  g.drawString("hello",0,0)
end


I have not succeed to puts any elements from AWT/Graphics

I guess my code is wrong but I don't know where...

boubek
Posted by Keith B. (keith_b)
on 2012-11-16 19:04
(Received via mailing list)
Wow, weird...I can't help you with why the method's not found, but as
far as printing stuff out for examination, you could try the File
methods method:

File.write('xyz.txt', "this is a test\n")

...or, to append to a file:

File.open('xyz.txt', 'a') { |f| f << 'appended text' }

I don't know where the applet's current directory would be; you could
always do something like this:

MY_FILESPEC = File.join(ENV['HOME'], 'myoutput.txt')

I don't know if the applet's security settings allow writing to files,
though.

This worked for me on Mac OS, even when stdout was redirected, when I
was in a terminal:

tty = File.open '/dev/tty', 'a'
tty.puts 'hello'

- Keith

Keith R. Bennett
http://about.me/keithrbennett
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.