How to use instance JRUBY_APPLET

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

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