Hi!

I have implemented a GUI in XUL with JavaScript and load it in my
Java-App using the concept from
http://developer.mozilla.org/en/docs/JavaXPCOM:Embedding_Mozilla_in_a_Java_Application_using_JavaXPCOM.
My current Java-code is:
[code]
import java.io.FileNotFoundException;
import java.io.File;
import org.mozilla.xpcom.*;


public class JavaXPCOM_test1 {

        public static void main(String[] args) {

                File grePath = null;
                LocationProvider locProvider;

                Mozilla mozilla = Mozilla.getInstance();
                GREVersionRange[] range = new GREVersionRange[1];
                range[0] = new GREVersionRange("1.8.0", true, "1.9", false);

                try {
                        grePath = Mozilla.getGREPathWithProperties(range, null);
                        locProvider = new LocationProvider(grePath);
                        mozilla.initEmbedding(grePath, grePath, locProvider);
                }

                catch (FileNotFoundException e) {
                        System.out.println("Fehler: FileNotFoundException");
                }
                catch (XPCOMException e) {
                        System.out.println("Fehler: XPCOMException");
                }

                System.out.println("File grePath = "+grePath);
                System.out.println("grePath.getPath = "+grePath.getPath());


                nsIServiceManager serviceManager = mozilla.getServiceManager();

                nsIAppStartup appStartup =
(nsIAppStartup)serviceManager.getServiceByContractID("@mozilla.org/toolkit/app-startup;1",
nsIAppStartup.NS_IAPPSTARTUP_IID);
            System.out.println("1: nsIAppStartup appStartup = "+appStartup);

            nsIWindowCreator windowCreator =
(nsIWindowCreator)appStartup.queryInterface(nsIWindowCreator.NS_IWINDOWCREATOR_IID);

            System.out.println("2: nsIWindowCreator windowCreator =
"+windowCreator);

            nsIWindowWatcher windowWatcher =
(nsIWindowWatcher)serviceManager.getServiceByContractID("@mozilla.org/embedcomp/window-watcher;1",
nsIWindowWatcher.NS_IWINDOWWATCHER_IID);
            System.out.println("3: nsIWindowWatcher windowWatcher =
"+windowWatcher);

            windowWatcher.setWindowCreator(windowCreator);
            System.out.println("4:
windowWatcher.setWindowCreator(windowCreator)");

            nsIDOMWindow win = windowWatcher.openWindow(null,
"chrome://editor/content", "JAVA_EDITOR",
"chrome,resizable,centerscreen", null);
            System.out.println("5: nsIDOMWindow win = "+win);

            windowWatcher.setActiveWindow(win);
            System.out.println("6: windowWatcher.setActiveWindow(win)");


            System.out.println("7: appStartup.run() START");
            appStartup.run();
            System.out.println("7: appStartup.run() FINISHED");


            System.out.println("try termEmbedding");
            try {
                System.out.println("mozilla.termEmbedding(); START");
                mozilla.termEmbedding();
                System.out.println("mozilla.termEmbedding(); FINISHED");
            }
            catch (XPCOMException e) {
                System.out.println("Fehler: XPCOMException");
            }
            System.out.println("finished termEmbedding");
                System.out.println("All done");

        } //static void main(String[] args)
} //public class JavaXPCOM_test1[/code]



Now i need to call a Java-method from within my JavaScript and call a
JavaScript-method from Java.

What is the simplest way to do this? I have read something that it is
possible with JavaXPCOM or LiveConnect. But I don't know what is
easyer, better and how to do it. I Think some example codes would save
a few days of work. Cause for somebody who allready has the code its no
prob to post a sample code that help many people needing it like me ;)

Another questions I have are:
1.)
In future I want both, run my App via the embedded GUI in Jave using
the code shown and run my gui in directly as xulrunner standalone app.
So I need a interface between java and javascript that works in both
cases.

2.)
When I run my Java-App with the shown code it stops at the line
[code]appStartup.run();[/code]
when my gui is displayed until I close the window.
Can I call another Java-method from JavaScript although the app stops
at lthis line? And what if I want to call a JavaScript-method from Java
now?

_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to