use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class UploadData method main.
public static void main(String[] args) {
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
engine.network().set(BeforeSendUploadDataCallback.class, params -> {
if ("POST".equals(params.urlRequest().method())) {
// Override the original POST data with a text data.
return BeforeSendUploadDataCallback.Response.override(TextData.of("<text-data>"));
}
return BeforeSendUploadDataCallback.Response.proceed();
});
Browser browser = engine.newBrowser();
browser.navigation().loadUrlAndWait(LoadUrlParams.newBuilder("http://localhost/").postData("key=value").build());
}
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class UserAgent method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).userAgent("My User Agent String").build());
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("User Agent");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("http://whatsmyuseragent.com/");
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class VoiceRecognition method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).googleApiKey("your_api_key").googleDefaultClientId("your_client_id").googleDefaultClientSecret("your_client_secret").build());
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Voice Recognition");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
// To test the voice recognition click the "Search by voice" icon in the search field.
browser.navigation().loadUrl("https://google.com");
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class DemoApp method main.
public static void main(String[] args) {
// Set your JxBrowser license key.
System.setProperty("jxbrowser.license.key", "ENTER YOUR LICENSE KEY HERE");
EngineOptions.Builder options = EngineOptions.newBuilder(HARDWARE_ACCELERATED);
// #docfragment "enable-remote-debugging-port"
// Enable the remote debugging port.
options.remoteDebuggingPort(9222);
// #enddocfragment "enable-remote-debugging-port"
// Creating Chromium engine.
Engine engine = Engine.newInstance(options.build());
Browser browser = engine.newBrowser();
// Print the web page's title once the page is loaded.
browser.navigation().on(LoadFinished.class, event -> {
System.out.println("Title: " + browser.title());
});
SwingUtilities.invokeLater(() -> {
final BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Demo App");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
engine.close();
}
});
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.navigation().loadUrl("https://google.com");
});
}
use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.
the class LoggingRedirectExample method main.
public static void main(String[] args) {
// Configure JxBrowser logging level.
Logger.level(Level.ALL);
// Get the JxBrowser logger.
java.util.logging.Logger jxBrowserLogger = LogManager.getLogManager().getLogger("com.teamdev.jxbrowser");
// Remove existing handlers attached to the JxBrowser logger.
for (java.util.logging.Handler handler : jxBrowserLogger.getHandlers()) {
jxBrowserLogger.removeHandler(handler);
}
// Add SLF4JBridgeHandler to the JxBrowser logger to route log records to the SLF4j.
jxBrowserLogger.addHandler(new SLF4JBridgeHandler());
// Creating and running Chromium engine.
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
browser.navigation().loadUrl("https://google.com");
engine.close();
}
Aggregations