Created
February 6, 2014 16:32
-
-
Save shannah/8847742 to your computer and use it in GitHub Desktop.
This file contains 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 com.mycompany.myapp; | |
import ca.weblite.codename1.mirah.MyForm; | |
import com.codename1.components.WebBrowser; | |
import com.codename1.io.Log; | |
import com.codename1.javascript.JSFunction; | |
import com.codename1.javascript.JSObject; | |
import com.codename1.javascript.JavascriptContext; | |
import com.codename1.ui.BrowserComponent; | |
import com.codename1.ui.Button; | |
import com.codename1.ui.Display; | |
import com.codename1.ui.Form; | |
import com.codename1.ui.Label; | |
import com.codename1.ui.events.ActionEvent; | |
import com.codename1.ui.events.ActionListener; | |
import com.codename1.ui.layouts.BorderLayout; | |
import com.codename1.ui.plaf.UIManager; | |
import com.codename1.ui.util.Resources; | |
import java.io.IOException; | |
public class MyApplication { | |
private Form current; | |
public void init(Object context) { | |
try { | |
Resources theme = Resources.openLayered("/theme"); | |
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0])); | |
} catch(IOException e){ | |
e.printStackTrace(); | |
} | |
// Pro users - uncomment this code to get crash reports sent to you automatically | |
/*Display.getInstance().addEdtErrorHandler(new ActionListener() { | |
public void actionPerformed(ActionEvent evt) { | |
evt.consume(); | |
Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown")); | |
Log.p("OS " + Display.getInstance().getPlatformName()); | |
Log.p("Error " + evt.getSource()); | |
Log.p("Current Form " + Display.getInstance().getCurrent().getName()); | |
Log.e((Throwable)evt.getSource()); | |
Log.sendLog(); | |
} | |
});*/ | |
} | |
public void start() { | |
if(current != null){ | |
current.show(); | |
return; | |
} | |
//Form hi = new MyForm(); | |
//hi.show(); | |
startJS(); | |
} | |
public void startJS(){ | |
Form f = new Form("Test JS"); | |
final BrowserComponent c = new BrowserComponent(); | |
f.setLayout(new BorderLayout()); | |
final Button b = new Button("Hello"); | |
b.addActionListener(new ActionListener(){ | |
public void actionPerformed(ActionEvent evt) { | |
JavascriptContext ctx = new JavascriptContext(c); | |
JSObject logger = (JSObject)ctx.get("{}"); | |
logger.set("log", new JSFunction(){ | |
public void apply(JSObject self, Object[] args) { | |
String msg = (String)args[0]; | |
Log.p("[Javascript Logger] "+msg); | |
} | |
}); | |
ctx.set("window.logger", logger); | |
c.executeAndReturnString("logger.log('This is a test message');"); | |
} | |
}); | |
f.addComponent(BorderLayout.CENTER, c); | |
f.addComponent(BorderLayout.SOUTH, b); | |
f.show(); | |
} | |
public void stop() { | |
current = Display.getInstance().getCurrent(); | |
} | |
public void destroy() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment