Skip to content

Commit

Permalink
Merge pull request #201 from leaningtech/interoperability-tutorial-files
Browse files Browse the repository at this point in the history
modified index.html
  • Loading branch information
theodoravraimakis authored Nov 11, 2024
2 parents 9969c0a + 72b48e0 commit 6b43a46
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions examples/Interoperability/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@

<body>
<h1>CheerpJ Java Interoperability Tutorial</h1>
<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>
</br>

<!-- 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;
Expand All @@ -27,6 +30,10 @@ <h1>CheerpJ Java Interoperability Tutorial</h1>
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(() => { });
}
Expand All @@ -35,27 +42,29 @@ <h1>CheerpJ Java Interoperability Tutorial</h1>
await cheerpjInit(
{
version: 8,
natives: {
Java_com_example_Example_sendToHTML,
Java_com_example_Example_nativeSetApplication
natives: {
Java_com_example_Example_sendToHTML,
Java_com_example_Example_nativeSetApplication
}
}
);
cheerpjCreateDisplay(400, 300);

await cheerpjRunJar('/app/example.jar');
// here we use the path '/app/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/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);
window.alert(response);

}
</script>
</body>
Expand Down

0 comments on commit 6b43a46

Please sign in to comment.