| | |
Programme Compiled but not Run
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 55
Reputation:
Solved Threads: 1
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.
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.
That would be because you did not follow life cycle of applet, you never actually initialized your applet
Java Sun Tutorials - Lesson Applets READ AND LEARN
•
•
•
•
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.
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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
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?
You need to create a very small static html page that contains a reference to your applet, then run appletviewer as follows
Java Syntax (Toggle Plain Text)
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
----------------------------------------------
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
![]() |
Similar Threads
- compile error (C++)
- Hi to you all (Community Introductions)
Other Threads in the Java Forum
- Previous Thread: Display an image using java GUI
- Next Thread: Problem using java.util.Scanner
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number object open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream






