?
Solved

Running Applets in Netbeans 4

Posted on 2005-04-13
3
Medium Priority
?
484 Views
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 :-(
0
Comment
Question by:mark_667
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
edwardiii earned 400 total points
ID: 13799764
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:

        /*
       * NewJApplet.java
       *
       * 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;
              screen2D.drawString(greeting,25,50);
          }
      }

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:

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

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>

0
 
LVL 1

Author Comment

by:mark_667
ID: 13800627
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 :-)
0
 
LVL 10

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

831 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