Web Hosting Tomcat, Java, JSP, Servlets, J2EE, PHP, MySQL

Cheap web hosting provider

30
Oct

TextField inputField; TextArea outputArea; Button B1,B2; List L;

Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Previous Table of Contents Next Event Handling Once you understand exactly how all of this looks and feels, we can proceed to handle the Events that will be generated by these Components. Normally, Java applets use specialized methods to handle Events, because this is easier than handling the Events directly. This is especially true for mouse-related events, which you are probably very familiar with from all of your Java game experience (see Chapter 4, Adding Interactivity, for more). However, for this applet, we are going to handle Events in the lowest-level Event handler: handleEvent(). Let s step through that code now: public boolean handleEvent(Event evt) { if( evt != null ) { // just in case /* first, we handle the List-related Events. The user is not allowed to talk to nobody, so we default to “All Participants” (index 0) */ if(evt.id == Event.LIST_DESELECT) { L.select(0); return true; } /* when the user makes a selection in the List, we adjust the label of Button B1 and then force Panel p1 to redraw and re-layout */ if( evt.id == Event.LIST_SELECT ) { if( L.getSelectedIndex() == 0) B1.setLabel(”say”); else B1.setLabel(”whisper”); p1.layout(); return true; } /* if the Event is an ACTION_EVENT generated by a TextField (we only have one TextField), then it should perform the same action as pressing Button B1 (either login, say, or whisper) */ if( evt.target.equals( inputField ) && evt.id == Event.ACTION_EVENT) evt.arg = B1.getLabel(); /* now, we check to see if we have an “arg” */ if( evt.arg != null) {

Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider

Comments are closed.

Home | About Us | Compare Plans | Standard Hosting | Business Hosting | Java Tomcat Hosting | Support | FAQ | Order Now!

Powered by Omnicus java hosting services. All rights reserved.
Entries (RSS) and Comments (RSS).