HOES question

3 views
Skip to first unread message

Dan Fare

unread,
Oct 13, 2008, 11:24:11 PM10/13/08
to sleep-de...@googlegroups.com
how would i go about using actionPerformed via HOES, i don't really
know java that well so i'm not sure how i could fire a subroutine in
sleep from java.. is there a way??

thanks
dan

Raphael Mudge

unread,
Oct 14, 2008, 12:03:57 AM10/14/08
to sleep-de...@googlegroups.com
Take a look at chapter 7 of the manual. This topic (and this
example) are covered there.

debug(7);
global('$frame $button $clicked');
import javax.swing.*;
import java.awt.*;

$frame = [new JFrame: "Test"];
[$frame setSize: 240, 120];
[$frame setDefaultCloseOperation: [JFrame EXIT_ON_CLOSE]];

$button = [new JButton: "Click me"];
[[$frame getContentPane] add: $button];
[$frame show];

$clicked = 0;

sub button_pressed {
# $0 is "actionPerformed"
# $1 is a java.awt.event.ActionEvent object
$clicked++;
[[$1 getSource] setText: "Clicked $clicked time(s)"];
}

# add &button_pressed as our action listener
[$button addActionListener: &button_pressed];

Sleep converts closures into proxy instances of Java objects when
needed. A Java method call on a closure passes $0 as the method name
and each arg as $1 .. $n. This only works with interfaces.

If you want to perform this conversion yourself (rather than relying
on Sleep to figure it out) use the newInstance function.

http://sleep.dashnine.org/manual/newInstance.html

-- Raphael

Dan Fare

unread,
Oct 14, 2008, 12:44:31 AM10/14/08
to sleep-de...@googlegroups.com
thanks for the help, i think i finally figured it out!
Reply all
Reply to author
Forward
0 new messages