@ECHO OFF
REM Copyright (C) Cay S. Horstmann 1997. All rights reserved.
REM Distributed with TextPad with the permission of Cay S. Horstmann,
REM (www.horstmann.com) joint author of "Core Java" (ISBN 0-13-081933-6).
REM
REM This crazy batch file does the following.
REM 1. It finds if the .java file contains the word Applet. If so, it assumes
REM    it is an applet. So don't confuse it with silly things like displaying
REM    "This isn't an applet."
REM 2. If it is an applet, it makes a quick-and-dirty HTML file. I am giving
REM    it the extension .HTM so that your well-crafted HTML files aren't
REM    overwritten. The weird sequence of quotation marks is necessary because
REM    ECHO can't echo unquoted "<" and ">" characters
REM 3. If it is an applet, appletviewer is started. Otherwise the java
REM    interpreter is started.
REM 4. If it is a console applet (not deriving from Frame), then the batch
REM    file pauses for you to admire the output.

if "%1"=="" goto end
if not exist %1.class javac %1.java

find "Applet" %1.java > NUL:
if ERRORLEVEL 1 goto notapplet

REM Tests added by Michael L. Croswell to protect existing files
if exist %1.HTML goto runHTML
if exist %1.HTM goto runHTM

REM Build an HTML (as a %1.HTM) if it doesn't exist in either of the two forms above:
REM Mercifully, appletviewer ignores the quotes outside the Applet tag
echo "<APPLET CODE="%1.class" WIDTH=400 HEIGHT=300 IGNORE=""></APPLET>" > %1.HTM

:runHTM
appletviewer %1.HTM
goto end

:runHTML
appletviewer %1.HTML
goto end

:notapplet
find "Frame" %1.java > NUL:
if ERRORLEVEL 1 goto notframe

java %1
goto end

:notframe
java %1
pause

:end
