X

Geertjan's Blog

  • February 21, 2008

Applet of the Week!

Geertjan Wielenga
Product Manager
I've been in touch with NetBeans user Corey Hunt over the last few days who was working on creating an applet that would make use of the NetBeans Visual Library. At first I didn't think it would be possible at all, but David Kaspar, the library's creator, assured me that it was. There were several problems to solve first, though. Some general guidelines follow:

  1. Work through the applet tutorial to understand how applets are constructed in NetBeans IDE.

  2. Next, add the Visual Library JAR and the Utilities JAR to your Java application and then integrate the Visual Library code into the applet. For example, this is Corey's code that does the job:

    public class AppletRes extends JApplet {
    private DemoGraphScene scene = new DemoGraphScene();
    private javax.swing.JScrollPane jScrollPane1;
    /\*\* Initializes the applet AppletRes \*/
    @Override
    public void init() {
    try {
    java.awt.EventQueue.invokeAndWait(new Runnable() {
    public void run() {
    initComponents();
    jScrollPane1 = new javax.swing.JScrollPane();
    jScrollPane1.setViewportView(scene.createView());
    add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }
    });
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }
    ....
    ....
    ....

  3. Then, once you've got your applet working, before attaching it to the web application (which is explained in the tutorial above), you need to make sure that the content of the two JARs (i.e., the Visual Library JAR and the Utilities JAR) are wrapped into the JAR that contains the applet. Here's the Ant target, something like this is needed in your build.xml file:

    <target name="-post-jar">
    <jar update="true" destfile="${dist.jar}">
    <zipfileset src="${libs.swing-layout.classpath}"/>
    <zipfileset src="${file.reference.org-netbeans-api-visual.jar-1}"/>
    <zipfileset src="${file.reference.org-openide-util.jar-1}"/>
    </jar>
    </target>

  4. At this point you have your JAR containing your applet, plus the content of the three JARs above. Now that JAR can be added to the web application, but it also needs to be signed. Follow the steps described here, which pretty much describes everything, and is a blog entry I'd forgotten having ever written, actually, until Corey pointed me back to it.

And that's about it! Corey sent me a link to the result. Below you see his face (yes that's Corey), which can be moved around, it can be zoomed in/out, and the label below the pic can be edited. And everything you see below is in an applet:

It is the first time that I've seen the Visual Library API alive and kicking on the web. In his final note on the above, Corey writes: "Like I said, not much, but it represents a lot of gained knowledge and I am pretty stoked. Now, I am off to add functionality." Here's hoping he'll tell me when he gets to the next stage so I can share it here!

Join the discussion

Comments ( 6 )
  • Wade Chandler Thursday, February 21, 2008

    I just wanted to let everyone know that you don't need to zip/jar everything up into one JAR for this to work as an applet. You can reference the JAR files using the archive attribute which may contain a common delimited list of JAR files. That helps surpass any META-INF and manifest issues were entries needed which may otherwise be overwritten.


  • Wade Chandler Thursday, February 21, 2008

    Ugg...

    "common delimited" should be "comma delimited"


  • Corey Hunt Thursday, February 21, 2008

    This is actually the code that did it.

    <target name="-post-jar" depends="Jarsigner">

    <jar update="true" destfile="${dist.jar}">

    <zipfileset src="${libs.swing-layout.classpath}"/>

    <zipfileset src="${file.reference.org-netbeans-api-visual.jar}"/>

    <zipfileset src="${file.reference.org-openide-util.jar}"/>

    </jar>

    <jar update="true" destfile="${dist.dir}/sTestApplet.jar">

    <zipfileset src="${libs.swing-layout.classpath}"/>

    <zipfileset src="${file.reference.org-netbeans-api-visual.jar}"/>

    <zipfileset src="${file.reference.org-openide-util.jar}"/>

    </jar>

    </target>

    I had to add the jars to the signed jar as well. Thanks for posting me. My mom will think I'm famous :)

    -Corey


  • ann laurence Thursday, February 21, 2008

    I have no idea what any of this means....but, I think Corey is, indeed, famous. Of course, I am also his Mom.


  • Benjamin Rew Thursday, February 21, 2008

    Wow, great job. Sorry Wade got all bummed out.

    Wade, do you need a hug?


  • Dimoklis Despotakis Monday, February 8, 2010

    This is old but a try is worthy i think\^\^

    I have signed (following the tutorial) and added required targets (as Corey depicted) for my VL Applet but it doesn't work. The best case i have until now is just to see the applet's window,nothing more. If you can please send me in my e-mail a piece of code that works (or here).


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services