Sub Process_Global
Private jframe As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
Button1.Text="Open File Dialog"
jframe.InitializeNewInstance("javax.swing.JFrame",Array(""))
' jframe.RunMethod("setSize", Array(30, 20)) 'optional
End Sub
Private Sub openFileDialog(frame As JavaObject) As String
Dim fileChooser As JavaObject
fileChooser.InitializeNewInstance("javax.swing.JFileChooser", Array(Null))
Dim result As Int = fileChooser.RunMethod("showOpenDialog", Array(jframe))
If result = fileChooser.GetField("APPROVE_OPTION") Then
Dim selectedFile As JavaObject = fileChooser.RunMethod("getSelectedFile", Null)
Dim filePath As String = selectedFile.RunMethod("getPath", Null)
Log("Selected file Path: " & filePath)
Dim FileName As String = fileChooser.RunMethodJO("getSelectedFile",Null).RunMethod("getName",Null)
Log($"Selected File name:${FileName}"$)
' Process the selected file here
Else
Log("No file selected.")
End If
End Sub
'to call it:
Private Sub Button1_Click
openFileDialog(jframe)
End Sub