How to define an AppearEvent in java

Asked by blackheat

Hi,guys:

I am writing an observe function in sikuli using java.

I read the thread
https://answers.launchpad.net/sikuli/+question/165763

but I failed to create an AppearEvent which will be used in targetAppeared() function as a parameter.

Have anyone had ever done something like that?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

look https://answers.launchpad.net/sikuli/+question/187435

there someone else tried to get it running and finally did.

but there is currently a bug in the Java based observe solution (the above question contains a temporary fix).

Revision history for this message
blackheat (choi-dongbo) said :
#2

Thanks for your reply but I am still unclear about the usage.
in the angrybird example in sikuli blog,the python codes writes:

# Match ended
def myHandler(event):
 click("1313262381063.png")
 event.region.stopObserver() #stop the observation

# Match didn't end
def myHandler2(event):
 click("E.png")
 event.region.stopObserver() #stop the observation

# Main function
for x in range(20, 300):
 # waiting the game to begin
 wait(5)

 #launch bird
 t = find("1313265392054.png")
 dragDrop(t, [t.x - 150, t.y + x])

 # waiting for map destruction ;-)
 wait(30)

 #restart game
 #onAppear("i.png", myHandler)
 onAppear("1313273123506.png", myHandler)

 onAppear("III.png", myHandler2)
 observe(20)

how to do the same thing in java?

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

--- in Java e.g.
s = new Screen();

// Match ended
SikuliEventAdapter myHandler = new SikuliEventAdapter {
    public void targetAppeared (AppearEvent evnt) {
        System.out.println("targetChanged called");
 evnt.match.highlight(1);
        s.click("1313262381063.png");
 evnt.region.stopObserver();
    }
}

// Match didn't end
SikuliEventAdapter myHandler2 = new SikuliEventAdapter {
    public void targetAppeared (AppearEvent evnt) {
        System.out.println("targetChanged called");
 evnt.match.highlight(1);
        s.click("E.png");
 evnt.region.stopObserver();
    }
}

// some code not specific for observe
//.....

s.onAppear("1313273123506.png", myHandler);
s.onAppear("III.png", myHandler2);
s.observe(20.0);

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Sorry, these 2 lines are copy/paste rubbish:

System.out.println("targetChanged called");
evnt.match.highlight(1);

and I mixed tabs and spaces on indent ;-)

Revision history for this message
blackheat (choi-dongbo) said :
#5

Thanks RaiMan, that solved my question.