### Initialize CheerpJ Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/FoilSim-Applet/index.html Call this function to initialize CheerpJ before running any applets. Ensure it's awaited for proper setup. ```javascript await cheerpjInit(); ``` -------------------------------- ### Initialize and Run Server with Cheerpj Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Server-Client/Server/server.html Use this snippet to initialize Cheerpj, configure Tailscale, create a display, and run a server application. Ensure you replace 'PasteYourKeyHere' with your actual Tailscale authentication key. ```javascript async function () { await cheerpjInit({ tailscaleAuthKey: "PasteYourKeyHere", tailscaleIpCb: (ip) => { let el = document.querySelector("#ip"); el.value = ip; }, }); cheerpjCreateDisplay(800, 600); await cheerpjRunJar("/app/Server.jar"); }() ``` -------------------------------- ### Initialize and Run Cheerpj Client Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Server-Client/Client/client.html This JavaScript code initializes Cheerpj with a Tailscale authentication key, creates a display, and runs a specified JAR file. It listens for the Enter key press on an input element to trigger the execution with the provided IP address. ```javascript async function start(ip) { await cheerpjInit({ tailscaleAuthKey: "PasteYourKeyHere", }); cheerpjCreateDisplay(800, 600); await cheerpjRunJar("/app/Client.jar", ip); }; let el = document.querySelector("#ip"); el.addEventListener("keydown", (e) => { if (e.key == "Enter") { start(el.value); } }); ``` -------------------------------- ### Initialize and Run Swing Browser Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Swing-Browser/browser.html Initializes Cheerpj with Tailscale authentication and runs a Swing-based browser application from a JAR file. Replace 'PasteYourKeyHere' with your actual Tailscale authentication key. ```javascript Browser (async function () { await cheerpjInit({ tailscaleAuthKey:"PasteYourKeyHere", }); cheerpjCreateDisplay(800, 600); await cheerpjRunJar("/app/SwingHTMLBrowser.jar"); })(); ``` -------------------------------- ### Initialize and Run CheerpJ Application Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/SwingSet3/index.html Initializes CheerpJ, creates a display area within a specified container, and then runs a Java JAR application. Ensure the container element exists in the HTML. ```javascript await cheerpjInit(); cheerpjCreateDisplay(-1, -1, document.getElementById("container")); await cheerpjRunJar(\"`/app${location.pathname}SwingSet3.jar`\"); ``` -------------------------------- ### Initialize CheerpJ and Run JAR Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Interoperability/index.html Initializes CheerpJ with native JavaScript functions and runs a specified Java JAR file. Ensure the JAR path is correct for your deployment environment. ```javascript let exampleInstance; async function Java_com_example_Example_sendToHTML(lib, str) { document.getElementById('javaOutput').innerText = "JavaScript received: " + str; console.log("Received input from Java: " + str); } async function Java_com_example_Example_nativeSetApplication(lib, myApplication) { window.myApplication = myApplication; console.log(window.myApplication); console.log(myApplication); console.log("setting application"); // Make the inputDiv visible after initialization document.getElementById('inputDiv').style.display = 'block'; /* This makes the function 'never' return */ return new Promise(() => {}); } (async () => { await cheerpjInit({ version: 8, natives: { Java_com_example_Example_sendToHTML, Java_com_example_Example_nativeSetApplication } }); cheerpjCreateDisplay(400, 300); // here we use the path '/app/cheerpj-meta/examples/Interoperability/example.jar' for deployment on the cloud // use the path '/app/example.jar' for local deployment // await cheerpjRunJar('/app/example.jar'); await cheerpjRunJar('/app/cheerpj-meta/examples/Interoperability/example.jar'); })(); ``` -------------------------------- ### Define Function to Send Input to Java Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Interoperability/projectTemplate/index.html Create a JavaScript function to capture user input and send it to the Java environment through CheerpJ. ```javascript async function sendInputToJava() { /*...*/ } ``` -------------------------------- ### Include CheerpJ Loader Script Source: https://github.com/leaningtech/cheerpj-meta/blob/main/README.md Include this script tag in your HTML to load the CheerpJ runtime. Ensure the version number matches your CheerpJ version. ```html ``` -------------------------------- ### Implement Native JS for Java Interaction Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Interoperability/projectTemplate/index.html Define JavaScript functions that will be called by Java. These functions handle receiving data from Java and updating the UI. ```javascript async function Java_com_example_Example_sendToHTML(lib, str) { // Update the UI with the received string } ``` -------------------------------- ### Send Input from JavaScript to Java Source: https://github.com/leaningtech/cheerpj-meta/blob/main/examples/Interoperability/index.html Retrieves text from an HTML input field and sends it to a Java method named 'processInput' via the CheerpJ application instance. This function is intended to be called from a user interface event. ```javascript async function sendInputToJava() { // Get the input text from the HTML input box const inputText = document.getElementById("inputText").value; console.log(inputText); // Call the Java method with the input text const response = await window.myApplication.processInput(inputText); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.