Open html file from applet
Hi,,
i need to open html file from applet, but i am unable to open the html file, please find the code and can u tell me where i did wrong
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/*
<applet code="Resource.class" width="400" height="400"></applet>
*/
public class Resource extends Applet implements ActionListener
{
Button b = null;
public void init(){
b= new Button("Click");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
try
{
URL adress = new URL(getDocumentBase(), "html_code.htm");
getAppletContext().showDocument(adress, "_blank");
System.out.println("Execut inside"+adress);
}catch(MalformedURLException e){
System.out.println("Eror in Display");
}
}
}
[928 byte] By [
kathirsea] at [2007-10-1 15:31:40]

Nothing wrong with the code, works for me for both sun jre as well as msjvm allthough
with msjvm I had to compile it in a different way:
javac -source 1.3 -target 1.1 Resource.java
and changed the html tag to:
<applet code="Resource" width="400" height="400"></applet>
for the sun jre I changed the applet tag to object:
<!--"CONVERTED_APPLET"--><!-- HTML CONVERTER -->
<script language="JavaScript" type="text/javascript"><!--
var _info = navigator.userAgent;
var _ns = false;
var _ns6 = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
//--></script>
<comment>
<script language="JavaScript" type="text/javascript"><!--
var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0) || (_info.indexOf("IRIX") > 0)));
var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));
//--></script>
</comment>
<script language="JavaScript" type="text/javascript"><!--
if (_ie == true) document.writeln('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=1,5,0,0"><noembed><xmp>');
else if (_ns == true && _ns6 == false) document.writeln('<embed ' +
'type="application/x-java-applet;version=1.5" \
CODE = "Resource" ' +
'scriptable=false ' +
'pluginspage="http://java.sun.com/products/plugin/index.html#download"><noembed><xmp>');
//--></script>
<applet CODE = "Resource"></xmp>
<PARAM NAME = CODE VALUE = "Resource" >
<param name="type" value="application/x-java-applet;version=1.5">
<param name="scriptable" value="false">
</applet>
</noembed>
</embed>
</object>
<!--
<APPLET CODE = "Resource"></APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
You failed to mention if you got to see the button at all and what the trace is:
To turn the full trace on (windows) you can start the java console, to be found here:
C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
In the advanced tab you can fill in something for runtime parameters fill in this:
-Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
if you cannot start the java console check here:
C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
I think for linux this is somewhere in youruserdir/java (hidden directory)
add or change the following line:
javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
for 1.5:
deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
The trace is here:
C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
I think for linux this is somewhere in youruserdir/java (hidden directory)
Print out the full trace of the exception:
try{...}catch(Exception e){e.printStackTrace();}