nasirbaig
|
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. |
Writing JAVA code in ruby for Monkeybar Project
Replies: 5 - Last Post: July 27, 2009 23:10
by: Logan Barnett
by: Logan Barnett
showing 1 - 6 of 6
Logan Barnett
|
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 |
Logan Barnett
|
Posted: June 06, 2009 15:24 by Logan Barnett
|
| Thanks! I'll change my profile preferences so I can drop in formatted code (: |
nasirbaig
|
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 |
Logan Barnett
|
Posted: July 27, 2009 23:10 by Logan Barnett
|
|
showing 1 - 6 of 6
Replies: 5 - Last Post: July 27, 2009 23:10
by: Logan Barnett
by: Logan Barnett







