All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.webfolder.ui4j.sample.EventHandling Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package io.webfolder.ui4j.sample;

import io.webfolder.ui4j.api.browser.BrowserEngine;
import io.webfolder.ui4j.api.browser.BrowserFactory;
import io.webfolder.ui4j.api.browser.Page;
import io.webfolder.ui4j.api.dom.Document;
import io.webfolder.ui4j.api.dom.Element;

public class EventHandling {

    public static void main(String[] args) {
        BrowserEngine browser = BrowserFactory.getWebKit();

        // navigate to blank page
        Page page = browser.navigate("about:blank");

        // show the browser window
        page.show();

        Document document = page.getDocument();
        Element body = document.getBody();

        body.append("");

        // find the input element with an id #txt and bind the listener to the input event
        document.query("#txt").get().bind("input", (h) -> {
            System.out.println(h.getTarget().getValue().get());
        });

        // find the button and bind the click listener
        document.query("input[type='button']").get().bindClick((h) -> {
            System.out.println("clicked!");
        });

        // focus to text input
        document.query("#txt").get().focus();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy