How to use instance JRUBY_APPLET


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|

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

I guess my code is wrong but I don’t know where…


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:‘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,

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

tty = ‘/dev/tty’, ‘a’
tty.puts ‘hello’

  • Keith

Keith R. Bennett