wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Run applet from command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Run applet from command line" Watch "Run applet from command line" New topic
Author

Run applet from command line

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Hello
To complie the application I write java Hello.java
execute Java Hello. How can I complie and run the Applet?
What command I shoudl use?
Thanks
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Mike,
One way to compile and run the applet is to use the appletviewer. Example code follows. (Another way is to place the applet tag in an html file and open that file in a browser)
cheerio
rowan
Compile
~~~
javac Hello.java
Run
~~~
appletviewer Hello.java
import java.applet.*;
import java.awt.*;
/*
< applet code = "Hello.class", height=200 width=200>
< /applet>
*/
public class Hello extends Applet{
public void paint(Graphics g){
g.drawString("Hello everybody", 50,50);
}
}
[This message has been edited by Marilyn deQueiroz (edited November 21, 2001).]
[This message has been edited by Rowan Brownlee (edited November 23, 2001).]
[This message has been edited by Rowan Brownlee (edited November 23, 2001).]
Sadaf Zaidi
Greenhorn

Joined: Oct 09, 2001
Posts: 29
You can run the appplet from command line by using appletviewer method.
appletviewer MyFistApplet.html
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
When I do the following
Compile -> javac Hello.java
Run -> appletviewer Hello.java
After I type the Run line it doesn't open the browser, in other words it doesn't take any actions.
Why is that?
Thanks
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
can I just write
>> appletviewer Hello
Does this will open a new browser and show the contents of the applet?


Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Mike,
I think the problem lies with the spacing in the applet tag. To display on the discussion page, there's a space between "<" and "applet", "<" and "/applet>". However, the spaces cause problems in running the applet.
If you remove the spaces, recompile and execute the command
appletviewer Hello.java, the appletviewer will open with an instance of the applet within it.
cheerio
rowan
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
...If you want to open the applet in a browser rather than the applet viewer, you need to generate an html page containing the applet tag code.
If you then open that page in your browser, the applet will execute within the browser, rather than in the appletviewer. The browser will read the applet tag, find that the file to be embedded is called Hello.class, (hopefully find the file in the same directory as the html page) and load the applet in an area sized 200 x 200 pixels.
cheerio
rowan
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Therefore, the line doesn't has any meaning! The line doesn't run the applet(Open in new Windo. So what the line does? Thanks a lot.
Run
~~~
appletviewer Hello.java
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
...well, it does mean something. It launches the appletviewer, which creates a frame like space on the screen, instantiates the Hello.class and puts it in the space. Appletviewer operates as a means to examine or preview an applet outside a web browser. It's also not so heavy on system resources.
If you'd rather not use appletviewer, there's always the alternative of having the browser execute it by opening an html page containing the applet tag code.
cheerio
rowan
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Thanks a lot
I don't know what is wrong , but when I write
appletviewer Hello -> do nothing

Here it is
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\mike>cd ..
C:\Documents and Settings>cd ..
C:\>cd Java
C:\JAVA>appletviewer MandelbrotApplet2
'appletviewer' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>appletviewer MandelbrotApplet2.java
'appletviewer' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>javac MandelbrotApplet2.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>cd
C:\JAVA
C:\JAVA>ls
'ls' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>dir
Volume in drive C has no label.
Volume Serial Number is D0C1-56D5
Directory of C:\JAVA
11/21/2001 05:19 AM <DIR> .
11/21/2001 05:19 AM <DIR> ..
11/23/2001 04:24 AM 2,802 ComplexNumber.class
11/15/2001 05:08 PM 4,498 ComplexNumber.java
11/21/2001 05:18 AM 1,706 MandelbrotApplet2$GraphAction.class
11/21/2001 05:18 AM 1,084 MandelbrotApplet2$MandelbrotCanvas.class
11/21/2001 05:18 AM 2,527 MandelbrotApplet2.class
11/15/2001 05:08 PM 2,921 MandelbrotApplet2.java
11/21/2001 05:20 AM 1,114 MandelbrotDialog.class
11/15/2001 05:08 PM 1,052 MandelbrotDialog.java
11/21/2001 05:20 AM 1,005 MandelbrotFrame.class
11/15/2001 05:08 PM 992 MandelbrotFrame.java
11/21/2001 05:24 AM 778 MandelbrotUtilities.class
11/15/2001 05:08 PM 1,144 MandelbrotUtilities.java
12 File(s) 21,623 bytes
2 Dir(s) 16,152,109,056 bytes free
C:\JAVA>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\mike\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=MIKE-MBHUT2BIOP
ComSpec=C:\WINDOWS\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\mike
LOGONSERVER=\\MIKE-MBHUT2BIOP
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0803
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\mike\LOCALS~1\Temp
TMP=C:\DOCUME~1\mike\LOCALS~1\Temp
USERDOMAIN=MIKE-MBHUT2BIOP
USERNAME=mike
USERPROFILE=C:\Documents and Settings\mike
windir=C:\WINDOWS
C:\JAVA>C:\jdk1.3.1_01\bin\appletviewer MandelbrotApplet.java
I/O exception while reading: C:\JAVA\MandelbrotApplet.java (The system cannot fi
nd the file specified)
C:\JAVA>C:\jdk1.3.1_01\bin\appletviewer MandelbrotApplet2.java
C:\JAVA>
C:\JAVA>C:\jdk1.3.1_01\bin\appletviewer MandelbrotApplet.java
Thanks
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Mike - do you have your path setup ok, as per installation instructions?
http://java.sun.com/products/jdk/1.2/install-windows.html
If you don't this might explain why you're getting that error message concerning appletviewer (+you need to include the file extension when calling appletviewer).
rowan
~~~~~~~
C:\JAVA>appletviewer MandelbrotApplet2
'appletviewer' is not recognized as an internal or external command,
operable program or batch file.
~~~~~~~~
[This message has been edited by Rowan Brownlee (edited November 23, 2001).]
Joanne Fire
Ranch Hand

Joined: Nov 22, 2001
Posts: 33
Hi Mike.
What version of Windows are you using? I think that version of JDK supports Windows 2000 and NT 4 and higher.
Originally posted by Mike Shn:
Thanks a lot
I don't know what is wrong , but when I write
appletviewer Hello -> do nothing

Here it is
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\mike>cd ..
C:\Documents and Settings>cd ..
C:\>cd Java
C:\JAVA>appletviewer MandelbrotApplet2
'appletviewer' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>appletviewer MandelbrotApplet2.java
'appletviewer' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>javac MandelbrotApplet2.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>cd
C:\JAVA
C:\JAVA>ls
'ls' is not recognized as an internal or external command,
operable program or batch file.
C:\JAVA>dir
Volume in drive C has no label.
Volume Serial Number is D0C1-56D5
Directory of C:\JAVA
11/21/2001 05:19 AM <DIR> .
11/21/2001 05:19 AM <DIR> ..
11/23/2001 04:24 AM 2,802 ComplexNumber.class
11/15/2001 05:08 PM 4,498 ComplexNumber.java
11/21/2001 05:18 AM 1,706 MandelbrotApplet2$GraphAction.class
11/21/2001 05:18 AM 1,084 MandelbrotApplet2$MandelbrotCanvas.class
11/21/2001 05:18 AM 2,527 MandelbrotApplet2.class
11/15/2001 05:08 PM 2,921 MandelbrotApplet2.java
11/21/2001 05:20 AM 1,114 MandelbrotDialog.class
11/15/2001 05:08 PM 1,052 MandelbrotDialog.java
11/21/2001 05:20 AM 1,005 MandelbrotFrame.class
11/15/2001 05:08 PM 992 MandelbrotFrame.java
11/21/2001 05:24 AM 778 MandelbrotUtilities.class
11/15/2001 05:08 PM 1,144 MandelbrotUtilities.java
12 File(s) 21,623 bytes
2 Dir(s) 16,152,109,056 bytes free
C:\JAVA>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\mike\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=MIKE-MBHUT2BIOP
ComSpec=C:\WINDOWS\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\mike
LOGONSERVER=\\MIKE-MBHUT2BIOP
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0803
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\mike\LOCALS~1\Temp
TMP=C:\DOCUME~1\mike\LOCALS~1\Temp
USERDOMAIN=MIKE-MBHUT2BIOP
USERNAME=mike
USERPROFILE=C:\Documents and Settings\mike
windir=C:\WINDOWS
C:\JAVA>C:\jdk1.3.1_01\bin\appletviewer MandelbrotApplet.java
I/O exception while reading: C:\JAVA\MandelbrotApplet.java (The system cannot fi
nd the file specified)
C:\JAVA>C:\jdk1.3.1_01\bin\appletviewer MandelbrotApplet2.java
C:\JAVA>
C:\JAVA>C:\jdk1.3.1_01\bin\appletviewer MandelbrotApplet.java
Thanks

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Currently I'm using Windows XP Pro and JDK 1.3 is installed.
Also the path is set correct.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Run applet from command line
 
Similar Threads
classpath
COmpile command in Red Hat linux
applet on apache error, class not found
low level programming in java?
problem in executing swing application