Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

Events

How are user events managed?

Java 1.0.2 event management

There are two releases of Java available at this time. Java 1.0.2 is the older release that is currently supported by the major web browsers. Java 1.1.1 is the newer release of Java that as of May 21, 1997 is not supported by the major web browsers. There are significant differences in the two releases. Event handling techniques have changed in Java 1.1.1. This article briefly discusses how to handle events using the Java 1.0.2 event management facilities.

Contact applet events

There are two user initiated events managed by the Contact applet.
1. The user selects a name from the List itemList.
2. The user presses the Button sendButton.
The user is expected to select a name first then press the button. The Contact applet invokes the browser's email program after the button is pressed only if a name was selected from the list. Selecting a name without pressing the button has no consequence.

action()

The action() method is inherited from the Component class which is a superclass of Panel. The action() method handles events for basic components such as Button, Checkbox, Choice, and TextField. The Contact applet overrides the action() method which receives two objects in its parameter list as seen here: public boolean action(Event evt, Object obj){ The Event object describes the event that occurred. The Object object contains different values depending on what type of event occurred. There are 10 variables for the Event object. This statement: if (evt.target instanceof Button){ tests the target variable to determine if the event that occurred was a Button event. Since we have only one Button we don't need to figure out which Button was pressed.

After the button is pressed, we retrieve the item index of the name that was selected from the list. This statement int selected_index = itemList.getSelectedIndex(); executes the getSelectedIndex() method of the List object to retrieve the integer value of the item that is currently selected. If no item is selected the method returns -1. So the statement: if (selected_index > -1) tests to make sure an item was selected before calling the invokeTransfer method. If no item was selected then a message is displayed to the user on the browser's status line with the following statement: showStatus("Please select a name first, then press the Send Mail button.");

invokeTransfer()

The invokeTransfer() method is called by the action() method when it is time to invoke the browser's email program. One argument is passed to the method as seen in this statement: final void invokeTransfer(int selected_item){ The selected_item variable contains the index of the item selected from the itemList as well as the index to the array email_address that contains the corresponding email address.

The try / catch construct illustrates the exception handling capabilities. A try block is a group of statements enclosed in brackets that is tested for an error condition. If an error occurs in the try block statements then the catch block code is executed. This provides a graceful mechanism to trap and report unexpected errors.

The getAppletContext() is an interface to the applet's environment, which in this case is the browser. This statement getAppletContext().showDocument(new URL("mailto:" + email_address[selected_item])); invokes the showDocument() method to pass a new URL object containing the email address from the array email_address[selected_item] to the browser's email program. This will invoke the browsers email program passing the selected email address as the recipient.

If the applet is unable to invoke the user's email program then a message will be displayed on the browser's status line using the showStatus method of the Applet class as follows: showStatus("Failed to connect to Email program for: " + email_address[selected_item]);

Previous Next



Up to => Home / Authoring / Java / Intro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers