Running Applets in Netbeans 4

Posted on 2005-04-13
Last Modified: 2013-11-23
I am using Netbeans 4 for Win XP and am making a applet. However, I cannot get Netbeans to run it as one and not a normal program. In the Linux version this can be changed by clicking the project icon in the task-bar on the left of the screen, selecting properties and changing the execution method. However, the Windows version does not seem to have this feature. I have tried making a new web project with existing an source, but this does not give me the option of using applets and I don't really know what i'm doing with that feature. I can run the applet through a browser easily enough, but it reads from the class file which is only updated when it is compiled in the IDE, but I cannot do this.

Please help :-(
Question by:mark_667
    LVL 10

    Accepted Solution

    Hi, mark 667.

    I did the following on a Win2k Pro machine running Netbeans 4.0.  I was able to create a JApplet in Netbeans, run it in Netbeans (e.g. with the AppletViewer), and then put together my own HTML page (although Netbeans created a runnable HTML page in my JavaLibrary/build/ directory.  You can take the HTML page Netbeans 4 creates, rename it and relocate it anywhere on your system and it will still pull up and execute the applet.  Here are the steps I took:

    1)     If you haven't already, create a Project, or add a new one in your Properties window (top menu, then File/New Project), right-click on the project (for me this is JavaLibrary1; because I
            usually build Java classes, I choose General/Java Class Library), select "New/Java Package", and name the package (I chose "Applets").

    2)     Right-click on the new package, and select New/JApplet. (Note--if you don't see the JApplet option, pick anything--for example "Java Class"--then click the Back button at the bottom
            of the resulting pop-up window and select "JApplet" in the "Java Classes" folder, then click Next).  Name your JApplet in the "Class Name" box and click Finish.

    3)     Add your Applet code.  Below is what I created:

           * Created on April 16, 2005, 7:10 PM

          package Applets;

          import java.awt.*;

           * @author Edwardiii
          public class NewJApplet extends javax.swing.JApplet
              String greeting;
              /** Creates a new instance of NewJApplet */
              public void init()
                  greeting = "Howdy";
              public void paint(Graphics screen)
                  Graphics2D screen2D = (Graphics2D)screen;

    4)     After you've coded your JApplet, right-click on its name in the Project window and do "Compile File."  Right-click again and do "Run File."  You should see your JApplet run in the mini
            AppletViewer window.  Not sure if this is where your running into problems?

    5)     Netbeans 4 stored my new JApplet class file in my systems Documents and Settings\edwardiii\JavaLibrary\build\classes\Applets directory.  The new JApplet java file was put in:
            C:\Documents and Settings\edwardiii\JavaLibrary1\src\Applets, and the HTML file generated was put in: C:\Documents and Settings\edwardiii\JavaLibrary1\build\classes.

    You can grab the HTML page Netbeans created and use it from anywhere on your system; I created my own HTML page with Notepad and placed it in the same directory as the NewJApplet
    class file.  Here is the code that allowed it to run:

         <APPLET codebase="file:/C:/Documents%20and%20Settings/edwardiii/JavaLibrary1/build/classes/" code="Applets/NewJApplet.class" height=150 width=300>

    You can use Netbeans 4 and its JApplet class to create applets in the same way I described above.  Note in the HTML file Netbeans created, it placed the following guidance, which may interest you:

    *** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER  ***

    If you need to modify this HTML launcher file (e.g., to add applet parameters),
    copy it to where your applet class is found in the SRC folder. If you do this,
    the IDE will use it when you run or debug the applet.

    Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in
    the Creating JAR page in the Project Properties dialog.

    For more information see the online help.

    <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>

    LVL 1

    Author Comment

    Thanks for the response edwardiii it was the 1st and 2nd stages of your answer which solved it. I thought you could just get a new applet file through the new project dialogue like in 3.6. The additional steps which I didn't know about left me a bit lost.

    Thanks :-)
    LVL 10

    Expert Comment

    That's good news:)  If my response helped address the issue, please click the "Accept" button located by my previous comment:)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    Suggested Solutions

    Title # Comments Views Activity
    factory design pattern vs abstract factoy design pattern 2 61
    scores100 challenge 3 67
    wordsWithout 49 64
    endX challenge 2 30
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now