The powerful JCreator tools give you a change to run an Applet "directly" in JCreator.
save the following code to RunApplet.java and compile it.
Create a tool in options
Commands: D:\j2sdk1.4.2_10\bin\java.exe (JAVA.EXE in your JDK folder)
Arguments: RunApplet "$[CurClass]" "$[FileDir]" "$[JavaHome]"
Initial Directory: YOUR FOLDER TO STORE RunApplet.class (this file)
the html text comes from BlueJ. thanks them a lot.
have fun.
CODE
/**
* Utility class to run Applet in JCreator 3.5x
*
* @author CharlesMeng@RRC
* @version November 5, 2005
*
* Configure a JCreator tool in tools menu like this:
*
* Commands: D:\j2sdk1.4.2_10\bin\java.exe (JAVA.EXE in your JDK folder)
* Arguments: RunApplet "$[CurClass]" "$[FileDir]" "$[JavaHome]"
* Initial Directory: YOUR FOLDER TO STORE RunApplet.class (this file)
*
*/
import java.io.*;
import javax.swing.*;
public class RunApplet
{
public static void main(String[] args)
{
// Check command line parameters, if absence, show the Help
if (args.length == 0)
{
String szHelp = "Please configure a JCreator tool like this\r\n\r\n";
szHelp += " Commands: D:\\j2sdk1.4.2_10\\bin\\java.exe\r\n";
szHelp += " Arguments: RunApplet \"$[CurClass]\" \"$[FileDir]\" \"$[JavaHome]\" \r\n";
szHelp += " Initial Directory: YOUR FOLDER TO STORE RunApplet.class";
JOptionPane.showMessageDialog(null, szHelp);
return;
}
// Get the applet class name
String szClassName;
if (args[0].endsWith(".class"))
{
szClassName = args[0].substring(0,args[0].length() - 6);
}
else
{
szClassName = args[0];
}
// HTML text
String html ="<html>\r\n";
html += "\r\n";
html += "<!-- This file automatically generated by RunApplet.class -->\r\n";
html += "<!-- It is regenerated automatically each time the -->\r\n";
html += "<!-- applet is run. Any manual changes made to file will be lost -->\r\n";
html += "<!-- when the applet is next run through RunApplet. Save into a -->\r\n";
html += "<!-- directory outside of the package directory if you want to -->\r\n";
html += "<!-- preserve this file. -->\r\n";
html += "\r\n";
html += "<head>\r\n";
html += "<title>" + szClassName + " Applet</title>\r\n";
html += "</head>\r\n";
html += "\r\n";
html += "<body>\r\n";
html += "\r\n";
html += "<h1>" + szClassName +" Applet</h1>\r\n";
html += "<hr />\r\n";
html += "<applet code=\"";
html += szClassName;
html += ".class\" width=\"500\" height=\"300\" codebase=\".\" archive=\"\" alt=\"Your browser understands the <APPLET> tag but isn't running the applet, for some reason.\">\r\n";
html += " Your browser is ignoring the <APPLET> tag! \r\n";
html += "</applet> <hr />\r\n";
html += "\r\n";
html += "</body>\r\n";
html += "\r\n";
html += "</html>\r\n";
//Generate the HTML file
File fileHtml = new File(args[1], "tmp.htm");
PrintWriter prtHtml;
try
{
prtHtml= new PrintWriter(new PrintStream(new FileOutputStream(fileHtml)));
prtHtml.write(html);
prtHtml.close();
}
catch (FileNotFoundException ex)
{
}
// Call appletviewer to show the applet
// String[] szEnv = {"path=" + args[1] +"\bin"};
String szCmd = "appletviewer.exe tmp.htm";
fileHtml = new File(fileHtml.getParent());
try
{
// Runtime.getRuntime().exec(szCmd, szEnv, fileHtml);
Runtime.getRuntime().exec(szCmd, null, fileHtml);
} catch (Exception ex) {
ex.printStackTrace();
}
System.exit(0);
}
}
* Utility class to run Applet in JCreator 3.5x
*
* @author CharlesMeng@RRC
* @version November 5, 2005
*
* Configure a JCreator tool in tools menu like this:
*
* Commands: D:\j2sdk1.4.2_10\bin\java.exe (JAVA.EXE in your JDK folder)
* Arguments: RunApplet "$[CurClass]" "$[FileDir]" "$[JavaHome]"
* Initial Directory: YOUR FOLDER TO STORE RunApplet.class (this file)
*
*/
import java.io.*;
import javax.swing.*;
public class RunApplet
{
public static void main(String[] args)
{
// Check command line parameters, if absence, show the Help
if (args.length == 0)
{
String szHelp = "Please configure a JCreator tool like this\r\n\r\n";
szHelp += " Commands: D:\\j2sdk1.4.2_10\\bin\\java.exe\r\n";
szHelp += " Arguments: RunApplet \"$[CurClass]\" \"$[FileDir]\" \"$[JavaHome]\" \r\n";
szHelp += " Initial Directory: YOUR FOLDER TO STORE RunApplet.class";
JOptionPane.showMessageDialog(null, szHelp);
return;
}
// Get the applet class name
String szClassName;
if (args[0].endsWith(".class"))
{
szClassName = args[0].substring(0,args[0].length() - 6);
}
else
{
szClassName = args[0];
}
// HTML text
String html ="<html>\r\n";
html += "\r\n";
html += "<!-- This file automatically generated by RunApplet.class -->\r\n";
html += "<!-- It is regenerated automatically each time the -->\r\n";
html += "<!-- applet is run. Any manual changes made to file will be lost -->\r\n";
html += "<!-- when the applet is next run through RunApplet. Save into a -->\r\n";
html += "<!-- directory outside of the package directory if you want to -->\r\n";
html += "<!-- preserve this file. -->\r\n";
html += "\r\n";
html += "<head>\r\n";
html += "<title>" + szClassName + " Applet</title>\r\n";
html += "</head>\r\n";
html += "\r\n";
html += "<body>\r\n";
html += "\r\n";
html += "<h1>" + szClassName +" Applet</h1>\r\n";
html += "<hr />\r\n";
html += "<applet code=\"";
html += szClassName;
html += ".class\" width=\"500\" height=\"300\" codebase=\".\" archive=\"\" alt=\"Your browser understands the <APPLET> tag but isn't running the applet, for some reason.\">\r\n";
html += " Your browser is ignoring the <APPLET> tag! \r\n";
html += "</applet> <hr />\r\n";
html += "\r\n";
html += "</body>\r\n";
html += "\r\n";
html += "</html>\r\n";
//Generate the HTML file
File fileHtml = new File(args[1], "tmp.htm");
PrintWriter prtHtml;
try
{
prtHtml= new PrintWriter(new PrintStream(new FileOutputStream(fileHtml)));
prtHtml.write(html);
prtHtml.close();
}
catch (FileNotFoundException ex)
{
}
// Call appletviewer to show the applet
// String[] szEnv = {"path=" + args[1] +"\bin"};
String szCmd = "appletviewer.exe tmp.htm";
fileHtml = new File(fileHtml.getParent());
try
{
// Runtime.getRuntime().exec(szCmd, szEnv, fileHtml);
Runtime.getRuntime().exec(szCmd, null, fileHtml);
} catch (Exception ex) {
ex.printStackTrace();
}
System.exit(0);
}
}











