home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-27 | 5.6 KB | 205 lines |
- //******************************************************************************
- // updatecontrols.java: Applet
- //
- //******************************************************************************
- import java.applet.*;
- import java.awt.*;
- import intrinsc.*;
- // *** Must run Java Type Library Wizard from ***
- // *** the tools menu to make import successful. ***
-
- //==============================================================================
- // Main Class for applet updatecontrols
- //
- //==============================================================================
- public class updatecontrols extends Applet
- {
-
- // The HTML controls on the web page
- ICombo javaList;
- IButton javaButton;
- ICheckbox javaCheckbox;
- IText javaText;
-
- // The field and button for updating the <select> control
- TextField newLstIndex = new TextField("4");
- java.awt.Button updateLst = new java.awt.Button("Select Option");
-
- // The field and button for updating the <input type=button> control
- String value1 = "New Name";
- String value2 = "Other Name";
- TextField newBtnValue = new TextField(value1);
- java.awt.Button updateBtn = new java.awt.Button("Change Button Caption");
-
- // The field and button for updating the <input type=text> control
- String value3 = "New Input";
- String value4 = "Other Input";
- TextField newTxtValue = new TextField(value3);
- java.awt.Button updateTxt = new java.awt.Button("Change Input Text");
-
- // The button for updating the <input type=checkbox> control
- java.awt.Button updateChk = new java.awt.Button("Change Checkbox");
-
- // updatecontrols Class Constructor
- //--------------------------------------------------------------------------
- public updatecontrols()
- {
- }
-
- // APPLET INFO SUPPORT:
- //--------------------------------------------------------------------------
- public String getAppletInfo()
- {
- return "Name: updatecontrols\r\n" +
- "Created with Microsoft Visual J++ Version 1.0";
- }
-
-
- // init()
- //--------------------------------------------------------------------------
- public void init()
- {
- resize(270, 130);
-
- // set up the form for output
- setLayout(new GridLayout(4,2,10,10));
-
- add(newLstIndex);
- add(updateLst);
-
- add(newBtnValue);
- add(updateBtn);
-
- add(newTxtValue);
- add(updateTxt);
-
- add(updateChk);
- }
-
- // destroy()
- //-------------------------------------------------------------------------
- public void destroy()
- {
- }
-
- // updatecontrols Paint Handler
- //--------------------------------------------------------------------------
- public void paint(Graphics g)
- {
- }
-
- // start().
- //--------------------------------------------------------------------------
- public void start()
- {
- }
-
- // stop()
- //--------------------------------------------------------------------------
- public void stop()
- {
- }
-
- // loadcontrols()
- // The loadcontrols() function is called from the VBScript code after the page
- // has completely loaded. VBScript passes in all of the controls so the Java
- // class can modify them.
- //--------------------------------------------------------------------------
- public void loadControls(Object htmlList,
- Object htmlButton,
- Object htmlText,
- Object htmlCheckbox) {
- // storing access to the HTML controls
-
- // javaVar = Cast htmlVar
- javaButton = (IButton) htmlButton;
- javaList = (ICombo) htmlList;
- javaText = (IText) htmlText;
- javaCheckbox = (ICheckbox) htmlCheckbox;
- }
-
- // action()
- // The following code will monitor for a click on any of the
- // java.awt.Button controls then each case will dispatch a call
- // using COM to the controls on the HTML page.
- //--------------------------------------------------------------------------
- public boolean action(Event evt, Object what) {
-
- // Update the <select> control
- if (evt.target == updateLst) {
- // Get the value in the TextField and convert it to an int
- int temp = Integer.valueOf(newLstIndex.getText()).intValue();
-
- // Insure that the value is within range
- if(temp < 0) temp = 0;
- int length = javaList.getlength();
- if(temp > length - 1) temp = length - 1;
-
- // Change the selection in the control
- javaList.putselectedIndex(temp);
-
- // Update the value in the TextField
- temp = (temp + 1) % length;
- newLstIndex.setText(Integer.toString(temp));
-
- // Event handled
- return true;
- }
-
- // Update the <input type=button> control
- if (evt.target == updateBtn) {
-
- // Get the text from the TextField
- String str = newBtnValue.getText();
-
- // Update the caption (value) on the button
- javaButton.putvalue(str);
-
- // Change the value in the TextField
- if(str.compareTo(value1) == 0)
- newBtnValue.setText(value2);
- else
- newBtnValue.setText(value1);
-
- // Event handled
- return true;
- }
-
- // Update the <input type=text> control
- if (evt.target == updateTxt) {
-
- // Get the text from the TextField
- String str = newTxtValue.getText();
-
- // Update the <input type=text> control
- javaText.putvalue(str);
-
- // Change the value in the TextField
- if(str.compareTo(value3) == 0)
- newTxtValue.setText(value4);
- else
- newTxtValue.setText(value3);
-
- // Event handled
- return true;
- }
-
- // Update the <input type=checkbox> control
- if (evt.target == updateChk) {
-
- // Toggle the state of the control
- if (javaCheckbox.getchecked())
- javaCheckbox.putchecked(false);
- else
- javaCheckbox.putchecked(true);
-
- // Event handled
- return true;
- }
-
- // Event not handled
- return false;
- }
-
- }
-