Results 1 to 2 of 2
  1. #1
    nvidia is offline Member
    Join Date
    Aug 2007
    Posts
    13
    Rep Power
    0

    Default IMPORTANT: Applet Problem Please Help!

    Hi am really new to applets. I am reading a book on creating applets and i am trying to create the HelloWorld applet. I am also using Netbeans for this. The code i have used is as follows.

    Java Code:
    import java.applet.Applet;
    import java.awt.Graphics;
    
    public class HelloWorld extends Applet
    {
        
        /** Creates a new instance of HelloWorld */
        public void init()
        {
            
         
        }
        
           public void paint(Graphics g) 
        {
           g.drawString("Hello Luong", 50, 25); 
        }
         
       
    }
    After reading this book it now tells me to compile it using the java compiler but everytime i try to compile this i ALWAYS get the message:

    <no main class found>

    can somebody tell me what i need to do cos i have seen this example in many tutorials and there is no main class. I have attached the project folder for viewing.

    In the book it also reads that i need to create an html file with the code:

    Java Code:
    <html>
    <head>
    <title>
    Simple Applet
    </title>
    </head>
    <body>
       Here is the output of my applet:
    <APPLET CODE = "HelloWorld.class" width = 150 height=25 </APPLET>
    
    </body>
    <html>
    But before adding the html code, i need to sort out the main class issue. Can somebody give me some advice.
    The location of my applet is
    C:\MyNBProjects\Concurrent Programming\HelloWorld.java
    Thanks
    Attached Files Attached Files

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default Using Appletviewer

    Your html file applet tag has a missing bracket ( > ) in it.
    I usually avoid using html/web launching of applets because of caching problems. The JRE/plug-in and my ms browsers both like to cache Applets and run them irrespective of changes to their class files.
    To avoid this I develop with appletviewer, one of the tools in the sdk/jdk bin. To use it include an applet tag in a comment in your source file. Then, after compiling, run it with "appletviewer AppletName.java" at the prompt.
    Here's my console output after compiling and running your applet (renamed to avoid name–clashing in your system). Trying to run it as an application generates the error: no main method found in the file.
    Java Code:
    C:\jexp>javac hw.java
    
    C:\jexp>appletviewer HW.java
    
    C:\jexp>java HW
    Exception in thread "main" java.lang.NoSuchMethodError: main
    You can add a convenience main in your applets so you can run them from the prompt with "java" if you like. Make a Frame and add the applet to the center section of the default BorderLayout. Configure and show the frame like you would for an applcation.
    Here's the applet I ran in the tests shown above:
    Java Code:
    //  <applet code="HW" width="200" height="200"></applet>
    //  to run: at the prompt>appletviewer HW.java
    import java.applet.Applet;
    import java.awt.*;
    
    public class HW extends Applet
    {
        /** Creates a new instance of HW */
        public void init()
        {
            setBackground(Color.pink);
        }
    
        public void paint(Graphics g) 
        {
            g.drawString("Hello Luong", 50, 25); 
        }
    }

Similar Threads

  1. Serious applet problem
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-25-2008, 05:01 PM
  2. applet problem plz HELP
    By shibajisanyal in forum Java Applets
    Replies: 1
    Last Post: 01-09-2008, 01:47 AM
  3. Referer Problem : very Important
    By berkdulger in forum Java Servlet
    Replies: 1
    Last Post: 07-17-2007, 04:59 PM
  4. Important : Referer Problem
    By berkdulger in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-17-2007, 01:25 PM
  5. Applet problem
    By Ed in forum Java Applets
    Replies: 2
    Last Post: 07-02-2007, 03:35 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
  •