### Access a Java Class

To be able to access a Java Class, a JavaObject can be used (requires the JavaObject library).
To get Java Class information, read the Oracle Java API documentation.
http://docs.oracle.com/javase/8/docs/api/
Note
JavaObject cannot access the "java class" methods (eg getClass). It is related to the way it handles static methods.
Use the jReflection library instead.
Hint
In the Oracle Documentation, the class is show at the top right, like
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JOptionPane
The class to be referenced in the JavaObject is the very last from the list, e.g. javax.swing.JOptionPane
Example Classes with Documentation link
AWT Toolkit
http://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html
Calendar
http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html
File
http://docs.oracle.com/javase/8/docs/api/java/io/File.html
Dialogs
To create dialogs, the Java Swing Library offers various methods.
http://docs.oracle.com/javase/8/docs/api/javax/swing/JOptionPane.html
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
Example Get Current Date & Time
Class information:
http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html
Reference:
java.util
Class Calendar
java.lang.Object
java.util.Calendar
Dim JO As JavaObject
JO.InitializeStatic("java.util.Calendar")
Dim JO2 As JavaObject = JO.RunMethod("getInstance", Null)
Dim strDateTime As String = JO2.RunMethod("getTime", Null)
Log(strDateTime)
OR as Sub
`Sub runUtilCalendarMethod(strMethod As String)
If strMethod.Length = 0 Then Return
Dim JO As JavaObject
Dim s As String = JO.InitializeStatic("java.util.Calendar").RunMethodJO("getInstance", Null).RunMethod(strMethod, Null)
Log(s)
End Sub`
' Get time
runUtilCalendarMethod("getTime")
Example Show Message Dialog
Class information:
http://docs.oracle.com/javase/8/docs/api/javax/swing/JOptionPane.html
Reference:
Class JOptionPane
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JOptionPane
Dim jo As JavaObject
jo.InitializeStatic("javax.swing.JOptionPane")
' Returns null
jo.RunMethod("showMessageDialog", Array As Object(Null, "Hello World"))
' With HTML formatted string
jo.RunMethod("showMessageDialog", Array As Object(Null, "

# Hello World

", "Title", 2))
Example accessing API Methods for a TextArea
Class information:
http://docs.oracle.com/javafx/2/api/javafx/scene/control/TextInputControl.html
Reference:
Class TextInputControl
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.control.Control
javafx.scene.control.TextInputControl
replaceSelection and setSelection
Dim JO As JavaObject = TextArea1
JO.RunMethod("replaceSelection", Array As Object("New Text"))
JO.RunMethod("setSelection", Array As Object(Start, End))
Example Beep
Class information:
http://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html
Reference:
java.awt
Class Toolkit
java.lang.Object
java.awt.Toolkit
Dim jo As JavaObject
jo.InitializeStatic("java.awt.Toolkit")
Dim toolkit As JavaObject = jo.RunMethod("getDefaultToolkit", Null)
toolkit.RunMethod("beep", Null)
Examples using WebView provide good understanding of further use
Get WebView WebEngine History as a List
This example shows how to handle a list returned from an API method.
Class information:
http://docs.oracle.com/javafx/2/api/javafx/scene/web/WebEngine.html
Reference:
javafx.scene.web
Class WebEngine
java.lang.Object
javafx.scene.web.WebEngine
Method = public WebHistory getHistory()
Returns the session history object.
Class information:
http://docs.oracle.com/javafx/2/api/javafx/scene/web/WebHistory.html
Reference:
javafx.scene.web
Class WebHistory
java.lang.Object
javafx.scene.web.WebHistory
Method = ObservableList getEntries()
Returns an unmodifiable observable list of all entries in the history.
' Define the WebView (which is usually done via the JavaFx Scene Builder)
Private wvwMain as WebView
' Assign the webview to a JavaObject
Dim joWV As JavaObject = wvwMain
' Get the history list as a object from the webengine and assign to a JavaObject
' This is done via the getEngine
Dim joHL As JavaObject = joWV.RunMethodJO("getEngine", Null).RunMethod("getHistory", Null)
' Convert the JavaObject into a list
Dim l As List
l.Initialize
' Get all entries and put on a list
l.AddAll(joHL.RunMethod("getEntries", Null))
' Show the list - only the url
Dim nl As List
nl.Initialize
'[url: http://www.google.de/?gfe_rd=cr&ei=nNK6U7CDFIym8weeiIG4BQ, title: Google, date: Mon Jul 07 19:02:24 CEST 2014]
For i = 0 To l.Size - 1
Dim s() As String = Regex.Split(",", l.get(i))
Dim url As String = s(0).Replace("[url: ", "")
If nl.IndexOf(url) = -1 Then nl.Add(url)
Next
Execute an API method
Dim result As Object = joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(cmd))
Depending on the API method, the result can be used. The result could be a boolean, string etc.
Get the Screensize
The AWT toolkit provides an API method to get the window screen size:
http://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html
Dim jo As JavaObject
jo.InitializeStatic("java.awt.Toolkit")
Dim toolkit As JavaObject = jo.RunMethod("getDefaultToolkit", Null)
Log(toolkit.RunMethod("getScreenSize", Null))
Example Output:
java.awt.Dimension[width=1920,height=1080]

Changed: , Category: JavaObject, File: T6C208M1515.htm, ID: 1515