Repository navigation
4. Send events from Java to the page
fakeivchenko edited this page Sep 28, 2026
·
1 revision
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
Tutorial
- Set up the project
- Open a window
- Call Java from the page
- Send events from Java to the page
- Draw your own title bar
- Export notes through a native dialog
- Keep the application in the tray
- Show notifications
- Give the application an icon and a name
- Build a native executable
- Package the application
Guides
- Pass objects through the bridge
- Stream bytes between the page and Java
- Open several windows
- Place and control a window
- Make a transparent window
- Add menus
- Register global shortcuts
- Show progress in the taskbar
- Use the clipboard
- Handle dropped files
- Zoom the page
- Set the window icon
- Follow the theme of the desktop
- Use cookies
- Store data in SQLite
- Keep secrets
- Show dialogs
- Run a single instance
- Open your own links and files
- Update the application
- Handle page permissions
- Handle links and page loads
Reference