<?xml version="1.0" encoding="utf-8"?>
<!-- 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
-->
<?xml-stylesheet type="text/xsl" href="https://mbien.dev/roller-ui/styles/rss.xsl" media="screen"?><rss version="2.0" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
  <title>Michael Bien&apos;s Weblog</title>
  <link>https://mbien.dev/blog/</link>
    <atom:link rel="self" type="application/rss+xml" href="https://mbien.dev/blog/feed/entries/rss?tags=fun" />
  <description>don&apos;t panic</description>
  <language>en-us</language>
  <copyright>Copyright 2024</copyright>
  <lastBuildDate>Sat, 24 Aug 2024 07:57:58 +0000</lastBuildDate>
  <generator>Apache Roller 6.1.4</generator>
  <item>
    <guid isPermaLink="true">https://mbien.dev/blog/entry/java_javascript_interoperability_example</guid>
    <title>Java - JavaScript Communication example</title>
    <dc:creator>mbien</dc:creator>
    <link>https://mbien.dev/blog/entry/java_javascript_interoperability_example</link>
    <pubDate>Tue, 12 May 2009 16:22:57 +0000</pubDate>
    <category>Java</category>
    <category>fun</category>
    <category>java</category>
    <category>javascript</category>
<description>&lt;p&gt;Communication between java applets and javascript code is already available &lt;a href=&quot;http://java.sun.com/products/plugin/1.3/docs/jsobject.html&quot;&gt;since J2SE 1.3&lt;/a&gt; (aka &lt;a href=&quot;http://en.wikipedia.org/wiki/LiveConnect&quot;&gt;LiveConnect&lt;/a&gt;, which was btw. &lt;a href=&quot;http://www.youtube.com/watch?v=4wi9Q1x8j7E&quot;&gt;rewritten from scratch&lt;/a&gt; in Java 6 update 10 as part of the new plugin) and is really easy to implement. It is a simple way to break out of the sandbox and do things which would usually require full system access (a signed applet + user approval via security dialog). For example applets living in a sandbox are only allowed to read mouse events via the AWT/Swing event mechanism which works as long the mouse is over the applet. &lt;/p&gt;&lt;p&gt;To read e.g the mouse position globaly you would need to call &lt;i&gt;MouseInfo.getPointerInfo().getLocation()&lt;/i&gt; which would cause a &lt;i&gt;java.security.AccessControlException: access denied.&lt;/i&gt; However, in javascript it is trivial to track mouse events for the whole html document (e.g google adds track onclick x,y events).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;

All you have to do is to use the object tag instead of applet tag (which is deprecated anyway) and give the object (applet) a name via the id attribute.&lt;/p&gt;&lt;pre style=&quot;border: 1px inset ; margin: 0px; padding: 3px; overflow: auto; text-align: left;&quot; dir=&quot;ltr&quot; class=&quot;alt2&quot;&gt;&amp;lt;&lt;font color=&quot;#ff0000&quot;&gt;&lt;b&gt;form name=&amp;quot;FishForm&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;gt;   &lt;br /&gt;    &amp;lt;object width=&amp;quot;256&amp;quot; height=&amp;quot;256&amp;quot; type=&amp;quot;application/x-java-applet&amp;quot; &lt;font color=&quot;#ff0000&quot;&gt;&lt;b&gt;id=&amp;quot;CrazyFish&amp;quot;&lt;/b&gt;&lt;/font&gt;&amp;gt;&lt;br /&gt;        &amp;lt;param value=&amp;quot;http://people.fh-landshut.de/~mbien/weblog/java_js_interop/launch.jnlp&amp;quot; name=&amp;quot;jnlp_href&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;param value=&amp;quot;false&amp;quot; name=&amp;quot;draggable&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/object&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&amp;nbsp;now you can simply call methods as usual.
&lt;/p&gt;&lt;pre style=&quot;border: 1px inset ; margin: 0px; padding: 3px; overflow: auto; text-align: left;&quot; dir=&quot;ltr&quot; class=&quot;alt2&quot;&gt;&amp;lt;script language=&amp;quot;JavaScript1.2&amp;quot;&amp;gt;&lt;br /&gt;     //...&lt;br /&gt;     document.onmousemove = onMouseMoved;&lt;br /&gt;&lt;br /&gt;     var tempX = 0;&lt;br /&gt;     var tempY = 0;&lt;br /&gt;&lt;br /&gt;     var applet = document&lt;font color=&quot;#ff0000&quot;&gt;&lt;b&gt;.FishForm.CrazyFish&lt;/b&gt;&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt;     function onMouseMoved(e) {&lt;br /&gt;         //...&lt;br /&gt;         // javascript -&amp;gt; java calls&lt;br /&gt;         applet.jsObjectOrigin(findPosX(applet), findPosY(applet));&lt;br /&gt;         applet.jsMouseMoved(tempX, tempY)&lt;br /&gt;         return true&lt;br /&gt;     }&lt;br /&gt;     //...&lt;br /&gt; &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&amp;nbsp;the other side is a plain old public method implemented in the java applet.&lt;br /&gt;&lt;/p&gt;


&lt;pre style=&quot;border: 1px inset ; margin: 0px; padding: 3px; overflow: auto; text-align: left;&quot; dir=&quot;ltr&quot; class=&quot;alt2&quot;&gt;&amp;nbsp;   /**&lt;br /&gt;     * called from javascript.&lt;br /&gt;     */&lt;br /&gt;    public void jsMouseMoved(int x, int y) {&lt;br /&gt;        //do something usefull&lt;br /&gt;    }&lt;/pre&gt;&lt;p&gt;&amp;nbsp;RIA/Web2.0 Observer Pattern in action ;)
&lt;/p&gt;
    &lt;form name=&quot;FishForm&quot; id=&quot;FishForm&quot;&gt;
        &lt;div id=&quot;FishBanner&quot;&gt;
            &lt;script&gt;
                var attribs = { width:256, height:256, id:&apos;CrazyFish&apos; };
                var params = { jnlp_href:&apos;http://people.fh-landshut.de/~mbien/weblog/java_js_interop/launch.jnlp&apos; };
                var banner0 = new Image(); banner0.src = &quot;//mbien.dev/blog/resource/banner_scripts/play.png&quot;;
                var banner1 = new Image(); banner1.src = &quot;//mbien.dev/blog/resource/banner_scripts/play-active.png&quot;;
            &lt;/script&gt;
	    &lt;a href=&quot;javascript:deployApplet(&apos;FishForm&apos;,&apos;FishBanner&apos;,attribs,params);startEvents();&quot;
                    onmouseover=&quot;play.src=banner1.src;&quot;
                    onmouseout =&quot;play.src=banner0.src;&quot;&gt;
                &lt;img id=&apos;play&apos; src=&quot;//mbien.dev/blog/resource/banner_scripts/play.png&quot; width=&quot;48&quot; height=&quot;48&quot; border=&quot;0&quot; hspace=&quot;100&quot; vspace=&quot;100&quot;/&gt;
            &lt;/a&gt;
        &lt;/div&gt;
    &lt;/form&gt;&lt;p&gt;

        &lt;script language=&quot;JavaScript1.2&quot;&gt;
            &lt;!--
            function startEvents() {
            // Detect if the browser is IE or not.
            // If it is not IE, we assume that the browser is NS.
            var IE = document.all?true:false

            // If NS -- that is, !IE -- then set up for mouse capture
            if (!IE) document.captureEvents(Event.MOUSEMOVE)

            document.onmousemove = onMouseMoved;

            var tempX = 0;
            var tempY = 0;

            var applet = document.FishForm.CrazyFish;

            function onMouseMoved(e) {
                if (IE) { // grab the x-y pos.s if browser is IE
                    tempX = event.clientX + document.body.scrollLeft
                    tempY = event.clientY + document.body.scrollTop
                } else {  // grab the x-y pos.s if browser is NS
                    tempX = e.pageX
                    tempY = e.pageY
                }
                // catch possible negative values in NS4
                if (tempX &lt; 0) {tempX = 0}
                if (tempY &lt; 0) {tempY = 0}

                // javascript -&gt; java calls
                applet.jsObjectOrigin(findPosX(applet), findPosY(applet));
                applet.jsMouseMoved(tempX, tempY)
                return true
            }

            function findPosX(obj) {
                var curleft = 0;
                if (document.getElementById || document.all)  {
                    while (obj.offsetParent) {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                    }
                }
                else if (document.layers)
                    curleft += obj.x;
                return curleft;
            }

            function findPosY(obj) {
                var curtop = 0;
                if (document.getElementById || document.all) {
                    while (obj.offsetParent)  {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                    }
                }
                else if (document.layers)
                    curtop += obj.y;
                return curtop;
            }
            }
            --&gt;
        &lt;/script&gt;
(The applet won&apos;t work with JRE version &amp;lt; 1.6 update 10 (or the equivalent on Mac OS) since I used the jnlp deployment mechanism, but it wouldn&apos;t have been necessary for this particular applet)&lt;/p&gt;&lt;p&gt;... and never forget Web 2.0 is watching you &lt;br /&gt;&lt;/p&gt;</description>  </item>
  <item>
    <guid isPermaLink="true">https://mbien.dev/blog/entry/netbeans_7_0_with_better</guid>
    <title>NetBeans 7.0 with better desktop integration planed</title>
    <dc:creator>mbien</dc:creator>
    <link>https://mbien.dev/blog/entry/netbeans_7_0_with_better</link>
    <pubDate>Tue, 1 Apr 2008 11:42:54 +0000</pubDate>
    <category>Java</category>
    <category>fun</category>
    <category>java</category>
    <category>netbeans</category>
<description>&lt;p align=&quot;justify&quot;&gt;&lt;b&gt;&lt;font color=&quot;#ff0000&quot;&gt;Note:&lt;/font&gt; &lt;/b&gt;This entry has been posted on &lt;b&gt;&lt;font color=&quot;#ff0000&quot;&gt;1. April&lt;/font&gt; &lt;/b&gt;2008 and &lt;u&gt;nothing&lt;/u&gt; of that below is true :-)&lt;/p&gt;&lt;div align=&quot;justify&quot;&gt;- - - - -&lt;br /&gt;&lt;/div&gt;&lt;p align=&quot;justify&quot;&gt;You probably already know a lot of changes are planed for the NetBeans 7.0 release.&lt;br /&gt;&lt;br /&gt;One of the bigger changes is tighter integration to the Windows Presentation Foundation for the SWT/JFace rewrite of NetBeans 7.0 similar tho the &lt;a href=&quot;http://java.dzone.com/news/microsoft-help-improve-vista-s&quot;&gt;Eclipse roadmap&lt;/a&gt;. The minimum system requirement will rise to windows vista ultimate with a DirectX 10 capable graphics card and a USB stick plugged into your system (swap file for java quickstarter) to render NetBeans 7 in full HD. The primary reason for that was the out of the box Java 6 incompatibility to apple systems (who knows maybe it is compatible with MacOS X but no one will tell you because if he tried installing SE 6 on macs he/she also signed an NDA...) and the issue that many architects simple do not understand the internals of linux distributions (e.g Ubuntu) to install NetBeans.&lt;br /&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt; On older cards or other operating systems JEdit will be started in compatibility mode (motif look&amp;amp;feel and full shell support).


The reason for that are the new consumer guidelines and download size limitations of the java 6 Update 10 release. (there is a because of backwards compatibility problems [to build 11] not fixable ArrayIndexOutOfBounds bug in the pack200 implementation - primary reason why the swing renderer does not fit into the NB 7 distribution anymore if started with Java 6 update 10).&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;This brings several advantages. E.g instead of playing &lt;a href=&quot;http://download.java.net/javadesktop/plugin2/jake2/&quot;&gt;Jake in the browser&lt;/a&gt; (update 10 required) NetBeans 7.0 will be capable to render Halo 3 in the editor pane (with full profiler integration and 16x FSAA text overlay). Regular patches will be available via update center.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Additionally to that better joystick support is planed. This should improve the navigation through larger projects and replace the &amp;quot;go to declaration&amp;quot; action. You may also activate the force feedback option in the new &amp;quot;user experience&amp;quot; tab in the options dialog to detect the files which causes unit tests to fail. (Note: not available in JEdit compatibility mode but there will be a blinking icon instead)&lt;br /&gt;&lt;/p&gt;&lt;p align=&quot;justify&quot;&gt;The higher costs to develop NetBeans 7.0 make a complete free distribution not feasible but it will be still free for opensource developers (but not without limitations e.g UML diagrams will be limited to only two kind of widgets &amp;quot;hack&amp;quot; and &amp;quot;ship&amp;quot; while maintaining 100% &lt;a href=&quot;http://weblogs.java.net/blog/chet/archive/2008/01/crystal_methodo.html&quot;&gt;SSP&lt;/a&gt; compatibility).&lt;br /&gt;&lt;/p&gt;</description>  </item>
</channel>
</rss>