Results 1 to 11 of 11
  1. #1
    towmtdj is offline Member
    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Default Problems with applets

    Hi everybody, I am new to this forum and Java too.
    I have been experimenting the use of applets in the last months , but couldn't find a way to make them work.
    My project is the simplest one, that is a basic applet which just overrides its "paint" method to make a simple string appear on the browser.
    Making a lot of trials, I learned that in the .html file which launches the applet (in the <applet ...> tag, the "code" atribute) you cannot specify a generic path, that is the .class you are launching must be in the same folder as the .html itself.
    But , in spite of this, no matter what I do , things don't change : I keep getting the same error, over and over again :

    "NoClassDefFoundError" (in the Java console).

    I am starting to lose any faith in the Java environment .....
    My applet is the most basic one, taken from a tutorial :

    package provaapplet;
    import java.awt.*;

    import java.awt.event.*;
    import java.applet.*;
    import java.awt.Graphics;


    public class ProvaApplet extends Applet {

    Label LB;

    public void paint (Graphics G )
    {
    super.paint(G);
    G.drawRect (10,10,100,100);
    G.drawString ("dio cristo", 20, 20);
    }

    }


    my .html file is as follows :

    <html>
    <head>
    <title>Applet test</title>
    </head>
    <body>

    <applet code="ProvaApplet.class" width=300 height=100/>

    </body>

    </html>



    I can see the html title appearing which means I am launching the right one, but the applet doesn't come out.
    I have been struggling with this for months , without any progress ....

    Any help ?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Problems with applets

    Please go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Problems with applets

    Does your source and build directory structure mirror the package declaration at the top of your code? and the class name needs to be qualified by the package name.

    More here:
    Lesson: Packages (The Java™ Tutorials > Learning the Java Language)
    Lesson: Java Applets (The Java™ Tutorials > Deployment)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    towmtdj is offline Member
    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Default Re: Problems with applets

    Quote Originally Posted by DarrylBurke View Post
    Does your source and build directory structure mirror the package declaration at the top of your code? and the class name needs to be qualified by the package name.

    More here:
    Lesson: Packages (The Java™ Tutorials > Learning the Java Language)
    Lesson: Java Applets (The Java™ Tutorials > Deployment)

    db

    By reading your answer , I realized that I had failed to include the package name in the .class specification in the "code" attribute in the <applet> tag . I did so because none of the books and tutorials I had read ( and I read a lot) ever mentioned this necessitiy. I wonder how does such people dare writing tutorials about the subject.
    Anyway it seems to finally work now.
    Thank you.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,936
    Rep Power
    19

    Default Re: Problems with applets

    Can I suggest learning JApplet (the "newer" Swing one) rather than the ancient Applet?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    towmtdj is offline Member
    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Default Re: Problems with applets

    Quote Originally Posted by Tolls View Post
    Can I suggest learning JApplet (the "newer" Swing one) rather than the ancient Applet?
    I appreciate your suggestion and help.... maybe it could be easier, but I am not used to solving problems by avoiding them .... If creating and old-style (that is, awt-based) applet is a problem for me , I think there's something basic I still don't get about the environment, so I dont't think switching to swing would help me fix my problems ....

    thank you anyway for your support

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,936
    Rep Power
    19

    Default Re: Problems with applets

    Well, no.
    It's not avoiding problems.
    No one (outside of school it seems) writes awt applications...you are, essentially, wasting your time learning it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Problems with applets

    Quote Originally Posted by towmtdj View Post
    I am not used to solving problems by avoiding them
    Ah. So you learned to write using a quill dipped in ink, did you? Or was it a hammer and chisel?

    More seriously, AWT is outdated. Swing replaced it more than 10 years ago, and is now in the process of being substituted by JavaFX 2 (which is still an immature technology, but not for long).

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Problems with applets

    I agree. One would think that even though Swing is built upon the awt framework that some of those direct superclasses would be deprecated for general use. The awt API documentation for Java 1.7 still doesn't even nudge the user towards JApplet or even JFrame for that matter. I haven't checked out the other awt classes.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  10. #10
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: Problems with applets

    Isn't Java 8 supposed to include drastic java GUI improvements? I know JavaFX is now included in Java7, and it looks nice.

  11. #11
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: Problems with applets

    Quote Originally Posted by Tolls View Post
    Well, no.
    It's not avoiding problems.
    No one (outside of school it seems) writes awt applications...you are, essentially, wasting your time learning it.
    My school doesn't even go over Applets anymore... they aren't really as relevant as they used to be and given all the security vulnerabilities and the consequent push to get java out of the browser, it might be not worth mastering. Other things like HTML5 and javascript are usually the replacements used where an "old-school" applet used to be deployed...

Similar Threads

  1. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  2. Problems viewing applets
    By teamvarsity87 in forum Java Applets
    Replies: 5
    Last Post: 02-24-2009, 01:58 AM
  3. Can't see any Applets
    By pyr0chem in forum Java Applets
    Replies: 9
    Last Post: 12-17-2008, 04:24 AM
  4. problems with applet session between to two applets
    By elizabeth in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 03:23 PM
  5. Problems to show images in applets
    By Felissa in forum Java Applets
    Replies: 1
    Last Post: 07-06-2007, 09:12 PM

Posting Permissions

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