CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1

    Exclamation Boneheaded Applet Question

    Hey everyone. I gave up on GridBagLayout for now, after discovering the usefullness of NetBeans 4.0 GUI form editor...

    But I now have a different issue.

    If I write an applet by hand that looks something like this:
    Code:
    public class Foo extends JApplet {
         public void init() {
              declare some stuff
             create containers
             create components
             add components to containers
         }
    }
    I can run that applet embedded in a basic html page and call the class involved like so:
    <applet class="Foo.class" archive="Foo.jar"> </applet>

    and when I load that page, my gui loads into the applet.

    However, after discovering the gui form editor, I tried creating a really nice gui using that.

    It too creates a form, as an applet but does it like so:
    Code:
    public class Foo extends javax.swing.JApplet {
       public void init() {
          try {
             java.awt.EventQueue.invokeAndWait(new Runnable() {
                        public void run() {
                               initComponents();
                        }
              });
           }  catch (Exception ex)  {
                  ex.printStackTrace();
           }
       }
       public void initComponents(){
          create container
          config container
          create componentA
          config componentA
          container.add(componentA, constraints)
          create componentB
          create componentB
          container.add(componentB, constraints)
          getContentPane().add(container, constraints)
       }
    }
    and thats about it. So when I call THAT applet from an HTML page, I get an error on loading.

    So here is the first question: if I use the form designer in NetBeans to create the GUI for the applet, what else do I need to add to get the gui to actually load and display? anything?

    The next question regards the error I am getting, and has little to do with my first question.
    after compiling the thing as a jar file, and trying to load it, the JRE throws and exception and I get this:
    class not found
    caused by java.io.FileNotFoundException (long path)/class.class

    so it is trying to find the class in my development directory, but not pulling it from the compiled jar file???

    Finally, the form designer does not import anything. It calles things directly. It does allow the use of AbsoluteLayout from org.netbeans.lib.awtextra however, which seems to work really well for creating a gui using specific item locations...
    BUT, once I create the jar file that is called by the browser when it renders the applet tag, will it be able to find that? IN other words, when I design somethign in C, C++, or VB, anything I include in the code is compiled in (libraries and classes), so the necessary stuff is pulled into the final executable.

    If I do this with an applet, when that applet is compiled from source to a jar file, does that process (using NetBeans and JDK 5.0) also pull in those external classes so that a JRE on a different machine will not have to call it??

    Sorry, that last question is just one that I haven't quite figured out yet. Java, I am finding, works a lot like other OO languages, howver, in some respects it is quite different...

    Thanks for the advice...
    Jeff

  2. #2
    Join Date
    Aug 2003
    Posts
    102

    Re: Boneheaded Applet Question

    Usually the ide packages your class file.............

    package Test;

    So to call that class file from a package, would be

    <applet class="Test.Foo" archive="Foo.jar"> </applet>

    check the source code or open up the jar file to see where the ide hid you class

  3. #3

    Re: Boneheaded Applet Question

    Thanks for the reply... I answered part of my own questions last night after posting my original issues...

    So, for those who read this: I am using NetBeans 4.1 and JDK 5.0. NetBeans 4.x (maybe also the 3.x versions) have a form designer feature that works somewhat like the designer in Visual Studio. You drag out the size of the applet or application, and click and drag components and layouts onto the UI. My problem first came from not being able to find the class involved. I fixed that issue quickly.

    The actual problem was that when I tried to run the applet via a simple HTML page that embedded the applet, the JRE threw an exception because it could not find the applet's class. This happened because i was calling it incorrectly. In previous applets and apps, I did not bother using package statements in my code, so this worked:

    Code:
    <applet class="Foo.class" archive="Foo.jar"></applet>
    HOWEVER, since I used the NetBeans applet template to do this one, it included a package statement. SO the fix there was simple enough...

    Code:
    <applet class="packagename/Foo.class" archive="Foo.jar"></applet>
    Then I got to my next issue. Not being able to find a particular included layout in my applet. NetBeans form designer inlcudes a layout style called AbsoluteLayout() that functions a lot like VB in that you drag your components to the place you want them, and the IDE takes care of the rest (which is a LOT easier than trying to get GridBagLayout to work by hand). The problem is that the AbsoluteLayout() class belongs to a set called by the IDE as org.netbeans.lib.awtextras which does not actually exist.

    After digging, I found the AbsoluteLayout.java and AbsoluteConstraints.java files in the NetBeans ide directory. Not in a Jar. To make my problems go away, I copied those java files into my project, and changed the statements that used the layout to reflect their new location. So now, I dont get class not found errors when compiling the applet.

    But that aside, I still have one outstanding question though... how are external classes included in a jar file?? In other words, if I use something from the standard libraries, such as javax.swing.Border or something like that, I really dont have to worry too much about where the method is coming from on execution. BUT, what if I design an app using a non-standard class?

    Lets say I create a class to be used for parsing and manipulating text. I'll call it the TextFunk class, and it is part of a package I built called jeff.javaclasses. thus, to implement something from this class, it would be imported or called like this:
    Code:
    import jeff.javaclasses.TextFunk.*;  //Or
    Blinkey NewFunkyness = new jeff.javaclasses.TextFunk.Blinkey;
    HOWEVER, after I compile this little applet, and put it on a website, where does that method come from when someone other than me accesses it? does the IDE pull the code into the Jar file (I assume this is so for import statments) or does it call it from the client machine's JRE??

    If it pulls the code into the Jar, that is great, because now I dont have to worry about someone in a different state not being able to run my app because he/she doesnt have a copy of jeff.javaclasses.jar.

    BUT, if it does NOT put the code into the jar file, then thre is a problem, because when someone else tries to run it, it no longer works properly because their JRE wont be able to find the class called jeff.javaclasses.TextFunk if they dont download and install that class file...

    Does that make sense? For now, I am including any classes I create as source code in my projects, but it would be much nicer to create one class file that I can store on my development box and call from any app I write without having to actually include the source code in each and every project package...

    Well, I said I was a newbie!

    Cheers
    Jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured