View Single Post
Old 07-26-2005, 02:33 PM   #4 (permalink)
timinator
Knows Where the Search Button Is
 
timinator's Avatar
 
Join Date: Jul 2005
Location: Washington
Model: 8300
Carrier: AT&T
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I finally figured this out. I'm surprised that something that should be so easy to do was so difficult to figure out. I guess it's due to the fact that I'm a C & C# developer, just now getting into java. Plus, the fact that the BB does things a little differently. Anyway, for the benefit of anyone else trying to figure this out, here's my sample code for determing which button is being selected. Enjoy.

Code:
// HelloWorld.java

class HelloWorld extends net.rim.device.api.ui.UiApplication 
{
    public static void main(String[] args)
    {
        HelloWorld instance = new HelloWorld();
        instance.enterEventDispatcher();
    }  
    public HelloWorld() 
    {
        pushScreen(new SalutationScreen());
    }
}
And here's the 2nd piece:
Code:
//SalutationScreen.java

import net.rim.device.api.ui.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class SalutationScreen extends MainScreen implements FieldChangeListener
{
    ButtonField testButton;
    ButtonField orButton;
    LabelField applicationTitle;
    
    public SalutationScreen()
    {
        super();
        applicationTitle = new LabelField("Hello World Title");
        setTitle(applicationTitle);
        
        testButton = new ButtonField("Click Me");
        testButton.setChangeListener(this);
        add(testButton);
        
        orButton = new ButtonField("Or Me");
        orButton.setChangeListener(this);
        add(orButton);
    }
    
    public void fieldChanged(Field field, int context)
    {
        if (field == testButton)
        {
            Dialog.inform("Click Me Button clicked.");
        }
        if (field == orButton)
        {
            Dialog.inform("Or Me Button clicked.");
        }
    }

    public boolean onClose()
    {
        Dialog.alert("Bye World!");    
        System.exit(0);
           return true;
    }
}
__________________
===================================
"There are 10 types of people in the world.
Those that understand binary and those that don't!"
www.timothytrimble.info - The ART of S/W Development
==================================
Offline