4. Send events from Java to the page - fakeivchenko/lwjwae GitHub Wiki
Java can also start the conversation. An event carries a name and a payload from Java to every listener on the page. In this step, Java announces each new note, and the page adds it to a list.
-
In
Main.java, emit an event after the note is stored:static void setUp(Window window) { window.bind( "saveNote", note -> { NOTES.add(note); window.emit("noteAdded", note); return "Saved " + NOTES.size() + (NOTES.size() == 1 ? " note" : " notes"); }); }
-
In
index.html, add a list after the status line:<p id="status"></p> <ul id="notes"></ul>
-
In
app.js, listen for the event:lwjwae.listen("noteAdded", (event) => { const item = document.createElement("li"); item.textContent = event.payload; document.querySelector("#notes").append(item); });
window.lwjwaeis the page side of the library. Besideslisten, it hasemitto send events to Java,windowto control the window,dialogfor native dialogs, andclipboard. -
Run the application and save a few notes:

Previous: Call Java from the page · Next: Draw your own title bar