Created
January 31, 2025 23:48
-
-
Save shannah/e8726f9293a0e742c9267d69bcd6d8eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ca.weblite.jcbtest; | |
import static com.codename1.ui.CN.*; | |
import com.codename1.system.Lifecycle; | |
import com.codename1.ui.*; | |
import com.codename1.ui.layouts.*; | |
import com.codename1.io.*; | |
import com.codename1.ui.plaf.*; | |
import com.codename1.ui.util.Resources; | |
/** | |
* This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose | |
* of building native mobile applications using Java. | |
*/ | |
public class JSCallbackTest extends Lifecycle { | |
@Override | |
public void runApp() { | |
Form hi = new Form("Browser", new BorderLayout()); | |
BrowserComponent browser = new BrowserComponent(); | |
browser.setURL("https://www.codenameone.com/"); | |
browser.addWebEventListener(BrowserComponent.onLoad, evt -> { | |
browser.addJSCallback("window.myCallback = function(args) {callback.onSuccess(args)};" | |
, (args) -> { | |
System.out.println("Hello: " + args); | |
}); | |
}); | |
hi.add(BorderLayout.CENTER, browser); | |
Button btn = new Button("Hello"); | |
btn.addActionListener(e -> { | |
browser.execute("myCallback('Hello from Java')"); | |
}); | |
hi.add(BorderLayout.SOUTH, btn); | |
hi.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment