Writing JAVA code in ruby for Monkeybar Project

  6 posts   Feedicon  
Replies: 5 - Last Post: July 27, 2009 23:10
by: Logan Barnett
showing 1 - 6 of 6
 
Posted: June 03, 2009 17:58 by nasirbaig
Hi There,

Is there a way to write java code in ruby.

Here the class in JAVA, which I need to write in ruby,


class MyMenuItem extends JMenuItem
{
private String commandstring = "";
public MyMenuItem(String str)
{
super(str);
commandstring= str;
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
System.out.println("Context got clicked"+commandstring);
}
});
}
}

I wrote following so far. I don't know how to add listener.


class MyMenuItem < javax.swing.JMenuItem
attr_accessor :commandstring

def initialize(str)
super(str)
@commandstring = str
#self.addMouseListener(java.awt.event.MouseAdapter.new()
#{})
end
end


Please let me know.

Thanking you in advance for your help.
 
Posted: June 03, 2009 19:54 by Logan Barnett
Man, sharing code on here is annoying - I'll just use pasties!
In JRuby, you can just pass a block into methods that only expect an interface (such as add listener methods):
http://pastie.org/499549

You can also create a listener object, and include the listener class
http://pastie.org/499550
 
Posted: June 06, 2009 08:57 by auxbuss

bb code doesn't seem to work but Markdown seems okay:

class MenuMouseListener
  include java.awt.event.MouseAdapter

  def mouseMoved(event)
  end
  # other mouse listener methods...
end

# then use it later in your menu
add_mouse_listener MenuMouseListener.new
 
Posted: June 06, 2009 15:24 by Logan Barnett
Thanks! I'll change my profile preferences so I can drop in formatted code (:
 
Posted: July 23, 2009 20:23 by nasirbaig
Hi There,

How should I write this JAVA code in ruby,

GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);



layout.setHorizontalGroup(
layout.createSequentialGroup()
.addComponent(c1)
.addComponent(c2)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(c3)
.addComponent(c4))
);


Please let me know.

Thanks
 
Posted: July 27, 2009 23:10 by Logan Barnett
layout = javax.swing.GroupLayout.new(panel)
@main_view_component.layout = layout
layout.horizontal_group = layout.create_sequential_group
  .add_component(c1)
  .add_component(c2)
  .add_group(layout.create_parallel_group(javax.swing.GroupLayout::Alignment::LEADING)
  .add_component(c3)
...
showing 1 - 6 of 6
Replies: 5 - Last Post: July 27, 2009 23:10
by: Logan Barnett
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close