mirror of
https://github.com/leaningtech/cheerpj-meta.git
synced 2025-03-15 01:54:48 +01:00
72 lines
2.5 KiB
HTML
72 lines
2.5 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>CheerpJ Java Interoperability Tutorial</title>
|
|
<script src="https://cjrtnc.leaningtech.com/3.1/cj3loader.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>CheerpJ Java Interoperability Tutorial</h1>
|
|
|
|
<!-- Wrap the input, button, and output in a div with an initial hidden style -->
|
|
<div id="inputDiv" style="display: none;">
|
|
<input type="text" id="inputText" placeholder="Type something here">
|
|
<button onclick="sendInputToJava()">Send to Java</button>
|
|
<div id="javaOutput" style="margin-top:20px; font-weight: bold;">JavaScript received: </div>
|
|
</div>
|
|
|
|
<script>
|
|
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');
|
|
|
|
})();
|
|
|
|
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);
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|