/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; import java.net.*; // URL, URLConnection, MalformedURLException; // import java.util.StringTokenizer; import java.io.*; public class StateHTM extends Applet { boolean debug = false; boolean check = false; String text = ""; String jsfile = "javascript:"; //defaults public void setCheck(boolean x) { checkbox1.setState(x); } public String getText() { text = textField1.getText() ; dbg("getText:"+text); return text; } void button1_Clicked(Event event) { // J2JS - HTML try{ if( jsfile.equals("javascript:")){ text = textField1.getText() ; dbg("click: javascript:"+text); getAppletContext().showDocument(new URL("javascript:"+text )); } else{ dbg("click: http://.."+jsfile+" HiddenFrame"); getAppletContext().showDocument(new URL(getDocumentBase(),jsfile), "HiddenFrame"); } } catch (MalformedURLException Me) { dbg( Me.toString()); textField1.setText(Me.toString()); } catch ( IOException e ) { dbg( e.toString() ); textField1.setText(e.toString()); } } void checkbox1_Action(Event event) { // to do: place event handler code here. check = checkbox1.getState(); } void button2_Clicked(Event event) { // setOther String param; StateHTM other; // param = (check ? "check=T" : "check=F"); check = checkbox1.getState(); param = getParameter("NAME"); if( param == null || param.equals("StateM1") ) { other = StaticM.M2; param = "StateM2"; } else { other = StaticM.M1; param = "StateM1"; } // other = (StateHTM) this.getAppletContext().getApplet(param); other.setCheck(check); } public String getAppletInfo() { return "Applet by Malcom Strandberg (c)1997 Davox Corporation"; } /** * Parameter Info */ public String[][] getParameterInfo() { String[][] info = { {"JSFILE", "string", "javascript:|j2js.html"}, {"DEBUG", "boolean", "T else F"}, {"CHECK", "boolean", "T else F"}, {"TEXT", "string", "anything"}, }; return info; } /** * Print silly debugging info. */ void dbg(String s) { if (debug) { System.out.println(s); } } public void init() { super.init(); String param = getParameter("DEBUG"); if (param != null) { debug = true; } param = getParameter("JSFILE"); if (param != null) { jsfile = param; } param = getParameter("CHECK"); if (param != null) { check = true; dbg("CHECK = true"); } text = getParameter("TEXT"); dbg("TEXT = "+text); //{{INIT_CONTROLS setLayout(null); addNotify(); resize(300,182); checkbox1 = new java.awt.Checkbox("checkbox"); checkbox1.reshape(48,72,96,34); add(checkbox1); button1 = new java.awt.Button("J2JS"); button1.reshape(36,24,86,36); add(button1); textField1 = new java.awt.TextField(); textField1.reshape(36,120,228,34); add(textField1); button2 = new java.awt.Button("setother"); button2.reshape(168,24,93,36); add(button2); //}} checkbox1.setState(check); textField1.setText(text); param = getParameter("NAME"); if( param == null || param.equals("StateM1") ) { StaticM.M1 = this; } else { StaticM.M2 = this; } } public boolean handleEvent(Event event) { if (event.target == button1 && event.id == Event.ACTION_EVENT) { button1_Clicked(event); return true; } if (event.target == checkbox1 && event.id == Event.ACTION_EVENT) { checkbox1_Action(event); return true; } if (event.target == button2 && event.id == Event.ACTION_EVENT) { button2_Clicked(event); return true; } return super.handleEvent(event); } //{{DECLARE_CONTROLS java.awt.Checkbox checkbox1; java.awt.Button button1; java.awt.TextField textField1; java.awt.Button button2; //}} } class StaticM { // files away the other handle public static StateHTM M1 ; public static StateHTM M2 ; }