home
NEWS       BLOGS       FORUMS       NEWSLETTERS       RESEARCH       EVENTS       DIGITAL LIBRARY       CAREERS  
Network Computing Network Computing Powered by InformationWeek Business Technology Network

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers



Netdesign Manual

Part 4

Java XML Programmers Reference

Chapter 11: XML Tools for Information Appliances


October 15, 2001


Brought to you by:





Check It Out!

Handling penDown() Events

By extending com.sun.kjava.Spotlet, ContactBook is able to receive a variety of user interface events by overriding Spotlet event handlers. In this case, we are only interested in knowing when the user has clicked one of our buttons. We'll override Spotlet.penDown() to determine this.

public void penDown(int x, int y) {
//exit btn pressed?
if (exitBtn.pressed(x,y))
System.exit(1);
//add btn pressed?
else if (addBtn.pressed(x,y)) {
AddContact ac = new AddContact(this);
}
//beam btn pressed?
else if (beamBtn.pressed(x,y)) {
BeamContact ba = new BeamContact(this);
}
//receive btn pressed?
else if (receiveBtn.pressed(x,y)) {
ReceiveContact ra = new ReceiveContact(this);
}
//search btn pressed?
else if (searchBtn.pressed(x,y)) {
SearchContact sc = new SearchContact(this);
}
}

Spotlet.penDown() receives the x and y screen coordinates, in pixels, where the stylus was pressed. The rest of the code calls com.sun.kjava.Button.pressed(), which returns Boolean true if (x,y) are within the Button boundaries, to determine if a Button was pressed. If a Button was pressed, one of the other user interface classes is called. We will discuss each of these in detail. The only exception is the quit Button, which terminates the program.

Let's take a look at the class, AddContact, that gets instantiated if the top-most Button is pressed.

AddContact

public class AddContact

extends com.sun.kjava.Spotlet

AddContact is the class that enables the user to add contact entries into the custom Palm database, JavaXMLProgRef. A custom Palm database, also called a user-defined database, is a database that is not one of the system-defined databases: the address, date book, memo pad, and to do list databases. We have chosen not to use the address database because it defines its own record format for contacts; we would not be able to natively store XML if we used it. Creating our own user-defined database allows us to store bytes in any format we choose, and we choose XML, of course!

AddContact displays a data entry form to the user for the following fields:

  • First name


  • Last name


  • Address


  • City


  • State/province


  • Zip/postal code


  • Country


  • Phone number

Three buttons are also displayed:

  • quit — return control to class ContactBook without saving the data entered (if any) in the form


  • save & quit — creates a new record in the JavaXMLProgRef database using current form values, then returns control to ContactBook and its screen


  • save & continue — creates a new record in the JavaXMLProgRef database using current form values, then erases all form field values so another contact can be entered.

Let's look at a screenshot:






We'll examine three parts of class AddContact:

  • The constructor


  • Saving the generated XML as a new record in the JavaXMLProgRef database


  • Generating XML from the form's eight com.sun.kjava.TextField objects

Constructor

The constructor allocates objects for the com.sun.kjava.Button and com.sun.kjava.TextField variables declared with private class scope. It also registers as a listener for user interface events via the com.sun.kjava.Spotlet event handlers.

public class AddContact extends Spotlet {
private Button quitBtn, saveQuitBtn, saveAddMoreBtn;
private ContactBookSpotlet _owner;
private TextField fname, lname, address, city, state, zip,
country, phone;
public AddContact(ContactBookSpotlet owner) {
//register for events
register(NO_EVENT_OPTIONS); 
_owner = owner;
quitBtn = new Button("Quit", 1, 140);
saveQuitBtn = new Button("Save&Quit", 33, 140);
saveAddMoreBtn = new Button("Save&Continue", 92, 140);
fname = new TextField("First Name", 5, 10, 150, 10);
lname = new TextField("Last Name", 5, 25, 150, 10);
address = new TextField("Address", 5, 40, 150, 10);
city = new TextField("City", 5, 55, 150, 10);
state = new TextField("State", 5, 70, 150, 10);
zip = new TextField("Zip", 5, 85, 150, 10);
country = new TextField("Country", 5, 100, 150, 10);
phone = new TextField("Phone", 5, 115, 150, 10);
paint(); //paint the screen
}
The TextField constructor's five arguments are similar. The first is the text or title that gets put in front of the text field (a colon is automatically appended to the supplied java.lang.String by the TextField class). The next four elements are measured in screen pixels and are, respectively, the upper (x,y) coordinates of the TextField, and the width (length) and height of the TextField. It's interesting to note that this simple UI element does not scroll if characters are entered after the full width of the element is occupied. Therefore, the maximum number of characters held by a TextField is determined by its width. Another oddity is that the Palm OS's use of a non-fixed-width font makes this maximum character length vary based upon the width of the characters entered (for example, less m's can be entered than l's)!

The last instruction in the constructor calls the paint() method, which we will skip since it is very similar to ContactBook.paint() (see Painting the Screen).


PAGE: 1 | 2 | 3 | 4 | 5 | 6 | 7 | NEXT PAGE
 





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Download Today
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



InformationWeek Business Technology Network
InformationWeekInformationWeek 500InformationWeek 500 ConferenceInformationWeek AnalyticsInformationWeek CIO
InformationWeek EventsInformationWeek ReportsInformationWeek MagazinebMightyByte and SwitchDark Reading
Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingNo JitterPlug Into The Cloud
space
Techweb Events Network
InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0 ConferenceMobile Business ExpoSoftware ConferenceCSI - Computer Security Institute
Black HatGTECEnergy CampMashup CampStartup Camp
space
Light Reading Communications Network
Light ReadingLight Reading EuropeUnstrungLight Reading's Cable Digital NewsConstantinopleInternet EvolutionPyramid Research
Heavy ReadingLight Reading Live!Light Reading InsiderEthernet ExpoOptical ExpoTeleco TVTower Technology Summit
space
Financial Technology Network
Advanced TradingBank Systems & TechnologyInsurance & TechnologyWall Street & TechnologyAccelerating Wall StreetBank Systems & Technology Executive SummitBuyside Trading SummitInsurance & Technology Executive Summit
space
Microsoft Technology Network
MSDN MagazineTechNetThe Architecture Journal
space


App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Technology Marketing Solutions  |  Advertising Contacts  |   Briefing Centers
Copyright © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights