Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-22-2008, 02:12 AM
Member
 
Join Date: Aug 2007
Posts: 12
nvidia is on a distinguished road
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.

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:

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
File Type: zip HelloWorld.zip (8.9 KB, 0 views)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-22-2008, 03:25 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
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.
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:
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); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serious applet problem willemjav Java Applets 1 03-25-2008 06:01 PM
applet problem plz HELP shibajisanyal Java Applets 1 01-09-2008 02:47 AM
Referer Problem : very Important berkdulger Java Servlet 1 07-17-2007 05:59 PM
Important : Referer Problem berkdulger JavaServer Pages (JSP) and JSTL 0 07-17-2007 02:25 PM
Applet problem Ed Java Applets 2 07-02-2007 04:35 PM


All times are GMT +3. The time now is 10:28 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org