// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package htmldemo;

import javax.swing.JApplet;

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 NewStyleSUN 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();
		}
	}
}
