Wish RunMethod for every nodes

jmon

Well-Known Member
Licensed User
Longtime User
Hi,

I think it would be very convenient to have a .RunMethod method for every node. So we would need to create new variables as JavaObject when running external methods.
Current:
Code: Copy
Dim l As Label
l.Initialize("")
l.Text = "Blah"
Dim lJo As JavaObject = l
lJo.RunMethod("setRotate", Array(90.0))

Suggested:
Code: Copy
Dim l As Label
l.Initialize("")
l.Text = "Blah"
l.RunMethod("setRotate", Array(90.0))

Or:
Code: Copy
Dim l As Label
l.Initialize("")
l.Text = "Blah"
l.asJo.RunMethod("setRotate", Array(90.0))

I currently use the asJo snippet from @Daestrum (https://www.b4x.com/android/forum/threads/javaobjects-the-easy-way.45121/), which is very good, but I found that this new proposition would be a great addition.

Thank you
Jmon.
 
Thanks

I was thinking about a general way of calling any Javafx method, like setPrefWidth, setMinWidth, setGraphic etc... that doesn't exist in B4J
At the moment I use the asJo method by daestrum, which I find convenient enough. This idea I propose is just to make the code simpler and cleaner, nothing more :)
 
If, in Erels example, you change n As Node to JavaObject, you don't need to create jo and can use n.RunMethod("...",...)
 
hi erel
RunMethod("setRotate", Array(Degrees))
what are the other parametres. eg. "setrotate","gettext", etc.
 
An all purpose sub - not quite what you wanted but flexible to allow for any method call
Code: Copy
...   
    Dim l As Label
    l.Initialize("")
    l.Text = "Hello"
    MainForm.RootPane.AddNode(l,20,20,-1,-1)
    RunMethod(l,"setRotate",Array(45.0))
End Sub
Sub RunMethod(n As JavaObject,method As String,args() As Object)
    n.RunMethod(method,args)
End Sub
 
  • Like
Reactions: eps
An all purpose sub - not quite what you wanted but flexible to allow for any method call
Code: Copy
...  
    Dim l As Label
    l.Initialize("")
    l.Text = "Hello"
    MainForm.RootPane.AddNode(l,20,20,-1,-1)
    RunMethod(l,"setRotate",Array(45.0))
End Sub
Sub RunMethod(n As JavaObject,method As String,args() As Object)
    n.RunMethod(method,args)
End Sub

Thanks for this - I've just re-purposed this and also added a return value as well :)

Code: Copy
Sub RunMethod(n As JavaObject,method As String,args() As Object) As Object

    Return n.RunMethod(method,args)

End Sub

:)
 
Back
Top