Re: Applets security and HTMLets
On 2/2/2013 12:49 PM, Stefan Ram wrote:
Arne Vajh?j <arne@vajhoej.dk> writes:
Java applets already have access to the HTML DOM.
If you refer to Live Connect: This needs JavaScript AFAIK.
Or what else did you think of?
Moreover, what would be nice, would be also Java Listeners
for web page events, like
<form name="input" action="MyJavaClass.class" method="java">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
, where ?MyJavaClass? is a class that implements the
interface ?HTMLFormListener? (to be defined) and gets the
form data (here, "user") via the HTMLFormEvent (to be defined).
<applet code="htmldemo.OldStyle.class" codebase="." archive="oldstyle.jar"
name="myapplet" width="1" height="1" mayscript>
</applet>
<form name="myform">
<input type="text" name="myfield1">
<br>
<input type="text" name="myfield2">
<br>
<input type="text" name="myfield3">
<br>
<input type="submit" value="Add" onclick="document.myapplet.calc();
return false">
</form>
package htmldemo;
import javax.swing.JApplet;
import netscape.javascript.JSObject;
public class OldStyle extends JApplet {
public void calc() {
JSObject window = JSObject.getWindow(this);
JSObject doc = (JSObject)window.getMember("document");
JSObject myform = (JSObject)doc.getMember("myform");
JSObject myfield1 = (JSObject)myform.getMember("myfield1");
JSObject myfield2 = (JSObject)myform.getMember("myfield2");
JSObject myfield3 = (JSObject)myform.getMember("myfield3");
int val1 =
Integer.parseInt(myfield1.getMember("value").toString());
int val2 =
Integer.parseInt(myfield2.getMember("value").toString());
int val3 = val1 + val2;
myfield3.setMember("value", Integer.toString(val3));
}
}
or:
<applet code="htmldemo.NewStyle.class" codebase="." archive="newstyle.jar"
name="myapplet" width="1" height="1" mayscript>
</applet>
<form>
<input type="text" id="myfield1">
<br>
<input type="text" id="myfield2">
<br>
<input type="text" id="myfield3">
<br>
<input type="submit" value="Add" onclick="document.myapplet.calc();
return false">
</form>
package htmldemo;
import javax.swing.JApplet;
import org.w3c.dom.Element;
import org.w3c.dom.html.HTMLDocument;
import org.w3c.dom.html.HTMLInputElement;
import com.sun.java.browser.dom.DOMAccessException;
import com.sun.java.browser.dom.DOMAccessor;
import com.sun.java.browser.dom.DOMAction;
import com.sun.java.browser.dom.DOMService;
import com.sun.java.browser.dom.DOMUnsupportedException;
public class NewStyle extends JApplet {
public void calc() {
try {
DOMService service = DOMService.getService(this);
service.invokeAndWait(new DOMAction() {
public Object run(DOMAccessor accessor) {
HTMLDocument doc = (HTMLDocument)
accessor.getDocument(NewStyle.this);
HTMLInputElement myfield1 =
(HTMLInputElement)doc.getElementById("myfield1");
HTMLInputElement myfield2 =
(HTMLInputElement)doc.getElementById("myfield2");
HTMLInputElement myfield3 =
(HTMLInputElement)doc.getElementById("myfield3");
int val1 = Integer.parseInt(myfield1.getValue());
int val2 = Integer.parseInt(myfield2.getValue());
int val3 = val1 + val2;
myfield3.setValue(Integer.toString(val3));
return null;
}
});
} catch (DOMUnsupportedException e) {
e.printStackTrace();
} catch (DOMAccessException e) {
e.printStackTrace();
}
}
}
At least the first stuff is intended to be used with JavaScript,
but there are not really any JavaScript involved.
Arne