public final class BrowserBuilder extends Object
public static void main(String... args) {
BrowserBuilder.newBrowser(java.lang.Object...).
loadClass(YourMain.class).
loadPage("index.html").
invoke("initialized", args).
showAndWait();
System.exit(0);
}
The above will load YourMain class via
a special classloader, it will locate an index.html (relative
to YourMain class) and show it in a browser window. When the
initialization is over, a public static method initialized
in YourMain will be called with provided string parameters.
This module provides only API for building browsers. To use it properly one also needs an implementation on the classpath of one's application. For example use:
<dependency> <groupId>org.netbeans.html</groupId> <artifactId>net.java.html.boot.fx</artifactId> <scope>runtime</scope> </dependency>
| Modifier and Type | Method and Description |
|---|---|
BrowserBuilder |
invoke(String methodName,
String... args)
Specifies callback method to notify the application that the browser is ready.
|
BrowserBuilder |
loadClass(Class<?> mainClass)
The class to load when the browser is initialized.
|
BrowserBuilder |
loadFinished(Runnable r)
Allows one to specify a runnable that should be invoked when a load
of a page is finished.
|
BrowserBuilder |
loadPage(String page)
Page to load into the browser.
|
static BrowserBuilder |
newBrowser(Object... context)
Entry method to obtain a new browser builder.
|
void |
showAndWait()
Shows the browser, loads specified page in and executes the
initialization method. |
public static BrowserBuilder newBrowser(Object... context)
loadClass(java.lang.Class) and
loadPage(java.lang.String).context - any instances that should be available to the builder -
implementation dependantpublic BrowserBuilder loadClass(Class<?> mainClass)
JavaScriptBody
and co.).mainClass - the class to load and resolve when the browser is readypublic BrowserBuilder loadFinished(Runnable r)
loadClass(java.lang.Class) and
invoke(java.lang.String, java.lang.String...) methods.r - the code to run when the page is loadedpublic BrowserBuilder loadPage(String page)
page represents
a URL known to the Java system, the URL is passed to the browser.
If system property browser.rootdir is specified, then a
file page relative to this directory is used as the URL.
If no such file exists, the system seeks for the
resource via Class.getResource(java.lang.String)
method (relative to the specified class).
If such resource is not found, a file relative to the location JAR
that contains the main class is
searched for.page - the location (relative, absolute, or URL) of a page to loadpublic BrowserBuilder invoke(String methodName, String... args)
loadClass(java.lang.Class) which takes an array of String
argument. The method is called on the browser dispatch thread one
the browser finishes loading of the HTML page.methodName - name of a method to seek forargs - parameters to pass to the methodpublic void showAndWait()
initialization method.
The method returns when the browser is closed.NullPointerException - if some of essential parameters (like page or
class have not been specifiedCopyright © 2014 NetBeans. All Rights Reserved.