Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim tf,tf1,tf2 As TextField
Dim keycode As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
tf.Initialize("tf")
tf.Tag = "tf"
tf1.Initialize("tf1")
tf1.Tag = "tf1"
tf2.Initialize("tf2")
tf2.Tag = "tf2"
keycode.InitializeStatic("javafx.scene.input.KeyCode")
MainForm.RootPane.AddNode(tf,10,10,100,20)
MainForm.RootPane.AddNode(tf1,10,40,100,20)
MainForm.RootPane.AddNode(tf2,10,80,100,20)
setHandler(tf,"setOnKeyPressed","tf_KeyPress")
setHandler(tf1,"setOnKeyPressed","tf_KeyPress")
setHandler(tf2,"setOnKeyPressed","tf_KeyPress")
End Sub
Sub tf_KeyPress_Event(MethodName As String, Args() As Object)
Log(Args(0))
Dim target As TextField = asJO(Args(0)).RunMethod("getTarget",Null)
Log("tf tag " & target.tag)
If asJO(Args(0)).RunMethod("getCode",Null) == keycode.GetField("UP") Then
' uppercase the text if 'up' is pressed
tf.text = tf.Text.ToUpperCase
asJO(tf).RunMethod("end",Null) ' make cursor stay at end of field
Log("up arrow pressed")
asJO(Args(0)).RunMethod("consume",Null)' eat the event to stop default behaviour
End If
End Sub
Sub asJO(o As JavaObject) As JavaObject
Return o
End Sub
Sub setHandler(ob As JavaObject,eventName As String,handlerName As String)
ob.RunMethod(eventName, Array(ob.CreateEventFromUI("javafx.event.EventHandler",handlerName,False)))
End Sub