ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Palm Programming with Waba
Pages: 1, 2, 3

Other GUI classes

We have discussed some of the basic, essential classes in the waba.ui package. You can certainly guess the uses of checkboxes and radio buttons. These are standard AWT classes as well, and their functionality in Waba is no different. However, there are a couple of classes that you would not encounter in other implementations of Java for the Palm.



MessageBox is a class which opens a modal window within another window. From the name you can probably ascertain its uses. It should be noted that MessageBox is part of SuperWaba (by Guilherme Campos Hazan), mentioned in last month's article. You can also create a message box with a number of buttons on it, such as Yes/No/Cancel. The getPressedButtonIndex() will tell you which of the three buttons the user pressed.

The Tab Control allows you to add tabs to a window, thus increasing your screen real estate. For example, if we were to enhance our contact manager to be a kind of tool for sales force personnel to use in tracking prospects as well as current customers, our application might look like this:

Palm screen shot.

The code for our newly enhanced version follows:

import waba.ui.*;

public class ContactManager extends MainWindow
{
TabPanel tabpanel;
Contacts contacts;

ContactManager()
{
setTitle("ContactManager");
}
public void onStart()
{
String tabs[] = new String[]{"Contacts","Prospects"};
tabpanel = new TabPanel(tabs);
tabpanel.setRect(0, 15, this.width, this.height);
tabpanel.setGaps(2,2,2,2);
contacts = new Contacts();
contacts.setRect(10,10,160,110);
tabpanel.getPanel(0).add(contacts);
add(tabpanel);
}

public void onEvent(Event event)
{
if (event.type == ControlEvent.PRESSED && event.target == tabpanel)
{
if (tabpanel.getActiveTab() == 0)
;// save contact information
else
; // prospect information.
}
}
}

class Contacts extends Container
{
Label lblName = new Label("Name");
Edit edtName = new Edit();
Label lblAddr = new Label("Address");
Edit edtAddr = new Edit();
Label lblEmail = new Label("email");
Edit edtEmail = new Edit();
Button button = new Button ("OK");
public Contacts()
{
lblName.setRect(10,10,60,12);
edtName.setRect(10,22,90,12);
lblEmail.setRect(10,34,60,12);
edtEmail.setRect(10,46,90,12);
lblAddr.setRect(10,58,60,12);
edtAddr.setRect(10,70,90,12);
button.setRect(10,90, 30,12);

add(lblName);
add(edtName);
add(lblEmail);
add(edtEmail);
add(lblAddr);
add(edtAddr);
add(button);
}
}

Note that we have broken out some of the interface into a separate class, Contacts.java. This will be placed inside the first tab. Setting up the tab interface is fairly easy. We declare a TabPanel (again, part of SuperWaba), and set its boundaries, initiate the Contacts object and set its bounds, then add the Contacts object to the TabPanel. Finally, we add the TabPanel to the main window.

The other difference is in the event handling code. We need to determine which tab we are dealing with using the getaActiveTab() method. After that, we can proceed with the processing to add a contact or, alternately, add a prospect.

This gives us a good idea how to set up a user interface in Waba. You should also look at the API documentation for examples of those classes undiscussed in this article. For further information on Waba, please consult the following links.

Matthew E. Ferris is President, Chicagoland Java User Group, a Sun Certified Java Programmer, and a contributing Author for Professional Java Server Programming, Wrox Press.


Return to ONJava.com.