Programme Compiled but not Run

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 55
Reputation: pardeep3dec is an unknown quantity at this point 
Solved Threads: 1
pardeep3dec pardeep3dec is offline Offline
Junior Poster in Training

Programme Compiled but not Run

 
0
  #1
Oct 1st, 2008
Dear Friends,
Here i am giving my programme coding and error.

file name - MyCanvas.java
import java.awt.*;
import java.applet.*;

public class MyCanvas extends Applet {
public MyCanvas() {
setSize(80, 40);
}
public void paint(Graphics g) {
g.drawRect(0, 0, 90, 50);
g.drawString("A Canvas", 15,15);
}
}


When i use command javac MyCanvas.java it is compile but when i use appletviewer
then it shows following error.

E:\pardeep\java\JAVAPROGRAMMES>javac MyCanvas.java

E:\pardeep\java\JAVAPROGRAMMES>appletviewer
Usage: appletviewer <options> url(s)

where <options> include:
-debug Start the applet viewer in the Java debugger
-encoding <encoding> Specify character encoding used by HTML files
-J<runtime flag> Pass argument to the java interpreter

The -J option is non-standard and subject to change without notice.

E:\pardeep\java\JAVAPROGRAMMES>




Please help i am new to java but i know c/c++ very well.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,252
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 492
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Programme Compiled but not Run

 
-1
  #2
Oct 1st, 2008
That would be because you did not follow life cycle of applet, you never actually initialized your applet
Life Cycle of an Applet: Basically, there are four methods in the Applet class on which any applet is built.
  • init: This method is intended for whatever initialization is needed for your applet. It is called after the param attributes of the applet tag.
  • start: This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other pages.
  • stop: This method is automatically called whenever the user moves away from the page containing applets. You can use this method to stop an animation.
  • destroy: This method is only called when the browser shuts down normally.
Java Sun Tutorials - Lesson Applets READ AND LEARN
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Programme Compiled but not Run

 
0
  #3
Oct 1st, 2008
Actually, it would be that he never told appletviewer which applet he wanted to view (although your information is good information, he never even got this far).

You need to create a very small static html page that contains a reference to your applet, then run appletviewer as follows
  1. appletviewer <full/or/relative/path/to/html/file>

Edit: One thing from the next post is true, you do not need to create an html page, you can add the applet tag as a comment at the top of the Applet Class as well then enter that as the argument to appletviewer. That does not change the original problem though, which was that you executed appletviewer without an argument, so how was it to know which applet to run?
Last edited by masijade; Oct 1st, 2008 at 5:20 am.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: gur is an unknown quantity at this point 
Solved Threads: 0
gur gur is offline Offline
Newbie Poster

Re: Programme Compiled but not Run

 
0
  #4
Oct 1st, 2008
its a right code..
just add applet tag n then try to run
/*<applet code="MyCanvas.java height=300 width=100>
</applet>*/

or save it as .html n then run in web browser
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 46
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 3
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

Re: Programme Compiled but not Run

 
0
  #5
Oct 3rd, 2008
just add applet tag and run this program as mentions in above reply....

enjoy
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC