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!

Contact Classes

The contact beamer application is really four applications in one. We have a "sender" application which is invoked to list and beam contact book entries. We also have a "receiver" application, which is invoked to listen for documents sent by the sender. A search tool allows the user to view and edit entries. Finally, a contact adder allows the user to insert new contact entries into the contact book. The deletion of individual contact entries in the database is left as an exercise to the reader! However, the entire contact book database can be deleted using the standard means to delete a .PDB/.PRC from the unit.

The application is comprised of five major classes:

Class ContactBook

  • The "main menu" of the application, this class simply displays four buttons to the user: add contacts, beam contacts, receive contacts, and quit

  • One of the next three classes are instantiated when a button is selected
Class AddContact

  • Displays a form into which the user enters information for a single contact: first name, last name, address, city, state/province, zip/postal code, country, phone number.

  • Allows the user to save the information as a new entry (or record) in the contact book database.
The ability to quickly enter multiple records is provided by Class BeamContact

  • Displays contact book entries (or records) to the user

  • Prompts the user to select an entry to beam

  • Builds a Contact XML document instance from the selected entry using NanoXML

  • Beams the document to another device
Class ReceiveContact

  • Displays a Waiting for beamed data message to the user

  • Blocks until a contact XML document is received

  • Prompts the user to import the contact entry into the local contact book database

  • Creates a new record in the contact book database if user chooses to keep the information
Class SearchContact

  • Displays a text field, asking for the user to display the search criteria

  • Searches all eight fields of each record in the database for the specified criteria

  • Displays matching records as buttons whose text is the first and last name of each matching contact

  • Waits for the user to press one of the buttons, then displays that contact entry and allows the user to modify it in the database

Other classes are used by these five classes, but those classes are from the NanoXML library discussed in a previous section of this chapter. We'll discuss the first four classes in the chapter; for brevity's sake we'll leave examination of class SearchContact to the reader. So now let's take a look at the only class with a main() method, ContactBook.

ContactBook

public class ContactBook

extends com.sun.kjava.Spotlet

ContactBook is the "main menu" of the application. It must extend com.sun.kjava.Spotlet to fit into the package com.sun.kjava application paradigm.

Spotlet is conceptually similar to java.applet.Applet in that it is a class for handling event callbacks. Overriding one of the event handlers, such as penMove(), keyDown(), or keyUp(), will enable the extended class (BeamAddress, in this case) to receive notification of these events.

ContactBook is quite simple. It displays five buttons to the user, then waits for user input. When one of the buttons is pressed, the flow of execution is handed off to class AddContact, class BeamContact, class ReceiveContact, class SearchContact, or it is terminated (if quit is selected). Here is a screenshot so you get a feel for how it looks:





We'll examine three parts of class ContactBook:

  • The constructor


  • Painting the screen


  • Handling penDown() events

Constructor

The constructor allocates objects for the com.sun.kjava.Button variables declared with private class scope:

public class ContactBook extends Spotlet {
private Button exitBtn, addBtn, beamBtn, receiveBtn;

public ContactBook() { exitBtn = new Button("Quit", 135, 140); addBtn = new Button("Add Contacts", 30, 50); beamBtn = new Button("Beam Contacts", 30, 70); receiveBtn = new Button("Receive Contacts", 30, 90); searchBtn = new Button("Search/View/Edit Contacts", 30, 90); paint(); //paint the screen

}
The Button constructor's three arguments are the button's text, and x and y screen coordinates in pixels. Most Palm OS devices have screens with 160x160 pixels, although Sony's new PEG-N710C doubles this to 320x320. We are assuming a 160x160 screen.

The last instruction in the constructor calls the paint() method, which brings us to our next topic.

Painting the Screen

Let's take a look at the paint() method, which is called to clear and paint the screen:

protected void paint() {
Graphics g = Graphics.getGraphics();
g.clearScreen(); //clear the screen
Unlike other GUI environments you might be used to, which may have multiple graphics objects and device contexts, there is only one and it's com.sun.kjava.Graphics object available to all Spotlets. It is a static singleton object in class Graphics. with this object that all screen painting is done. The above code cleared the screen; now let's draw a title and buttons:
//draw the title
g.drawString("What would you like to do?", 30, 10);
//draw the buttons
exitBtn.paint();
addBtn.paint();
beamBtn.paint();
receiveBtn.paint();
searchBtn.paint();
}
Graphics.drawString() is pretty self-explanatory. The first argument is the string to paint, while the next arguments are the x and y screen coordinates, respectively, in pixels. The Button.paint() method simply paints the button on the screen with its defined button text and screen coordinates.


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