B4J Question Canvas question

moore_it

Well-Known Member
Licensed User
Longtime User
How i do to check if i enter or exit in an canvas ?
MouseMoved event check only if yu're in canvas not if you're out of it.

Thanks in advance.
 

Daestrum

Expert
Licensed User
Longtime User
You could use something like this
c = the object ie the canvas
"..." = the name of the event
"c" = the sub prefix to use
B4X:
   ...
    setHandler(c ,"setOnMouseEntered", "c")
   ...
which calls this sub to set a handler
B4X:
Sub setHandler(ob As Object,eventName As String,handlerName As String)
    jo = ob
    myEventHandler = jo.CreateEventFromUI("javafx.event.EventHandler", _
                                                        handlerName,False)
    jo.RunMethod(eventName, Array(myEventHandler))
End Sub
which will call this sub when the mouse enters c
B4X:
Sub c_Event(MethodName As String, Args() As Object)As Object
    Log("mouse in C " & showEventType(Args(0)))
End Sub

Oops, forgot to add Dim myEventHandler in Process_Globals as an object and
jo as a javaobject
 
Last edited:
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
Ok Found It ...
TKS to Daestrum

Define objects

Private jo As JavaObject
Private myEventHandler AsObject

Set the handlers

cvs.Initialize("cvs")
setHandler(cvs ,"setOnMouseEntered","cvi")
setExitHandler(cvs ,"setOnMouseExited","cve")


Sub setHandler(ob As Object,eventName As String,handlerName As String)
jo = ob
myEventHandler = jo.CreateEventFromUI("javafx.event.EventHandler",handlerName,False)
jo.RunMethod(eventName, Array(myEventHandler))
End Sub

Sub setExitHandler(ob As Object,eventName As String,handlerName As String)
jo = ob
myEventHandler = jo.CreateEventFromUI("javafx.event.EventHandler",handlerName,False)
jo.RunMethod(eventName, Array(myEventHandler))
End Sub

Events

Sub cvi_Event(MethodName As String, Args() As Object)As Object

Log("mouse in Cvs " & Args(0))

End Sub

Sub cve_Event(MethodName As String, Args() As Object)As Object

Log("mouse out of Cvs " & Args(0))

End Sub
 
Upvote 0
Top