//
// bb_ibm_demo_screen.java
//
// MSI Services, Inc.
// Frank Ableson
// 973.448.0070
// fableson@msiservices.com
// code free to use for any purpose, commercial or otherwise
package com.msi.ibm;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Dialog;
// user interface for our application
// extends MainScreen - easy way to establish a GUI
// implements an interface for handling the button click
class bb_ibm_screen extends MainScreen implements FieldChangeListener
{
// private members - these represent the "controls"
private BasicEditField identifierfield = null;
private BasicEditField datafield = null;
private ButtonField submitbutton = null;
private LabelField statusfield = null;
// constructor
public bb_ibm_screen()
{
// invoke the constructor of the super class (MainScreen)
super();
// give our application window a title
setTitle("BB IBM Demo App");
// create user interface components
createui();
}
private void createui()
{
try
{
// create a field for entering the "identifier" of our transaction
identifierfield = new BasicEditField("Identifier: ","",50, EditField.NO_NEWLINE );
// add this field to the screen
add(identifierfield);
// create a field for the data of our transaction
datafield = new BasicEditField("Data: ","",100, EditField.NO_NEWLINE );
// add this field to the screen
add(datafield);
// create a button to submit out transaction
submitbutton = new ButtonField("Submit Transaction",ButtonField.CONSUME_CLICK);
// tell this button who handles changes (selection)
submitbutton.setChangeListener(this);
// add this button to the screen
add(submitbutton);
// add a status label
statusfield = new LabelField("Please enter transaction data.");
// add label to screen
add(statusfield);
}
catch (Exception e)
{
System.out.println("Failed to create user interface components");
}
}
// this method implements the FieldChangedListener Interface
// it is used to detect when the button is selected
// after validating that the input data is correct, it attempts to submit a transaction to the server
public void fieldChanged(Field f, int context)
{
// which field was changed
if (f == submitbutton)
{
// check fields....
String id = identifierfield.getText();
String data = datafield.getText();
if (id.trim().length() == 0 || data.trim().length() == 0)
{
Dialog.alert("Please fill in all fields.");
identifierfield.setFocus();
return;
}
// ok, looks like we have some good data
if (bb_ibm_transaction.ProcessTransaction(id,data) == true)
{
// transaction was submitted successfully, let's reset the GUI for easy entry to another field
identifierfield.setText("");
datafield.setText("");
identifierfield.setFocus();
statusfield.setText("Transaction Sent.");
// if you preferred to just close this applicaiton after submission, uncomment out the following line
//onClose();
}
}
}
// onClose method
public boolean onClose()
{
// end our application
System.exit(0);
return true;
}
}