BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-15-2007, 04:55 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jan 2007
Location: Wisconsin
Model: 8100
Carrier: tmobile
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Basic code to create a button and a listening method?

Please Login to Remove!

I have limited java experience, even smaller on these phones

I am having some trouble making a few simple buttons on the screen. I want like 4 buttonfields on the screen, and then a listening section for each button that will run a bit of code depending on which button is pressed. Could anyone give me a very simple example structure on how you would do this for multiple buttons?
Offline  
Old 04-16-2007, 01:36 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

try out this code
Code:
package com.rim.samples.device.test;

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


class Test1 extends UiApplication {
    public static void main(String[] args) {
        Test1 theApp = new Test1();
        theApp.enterEventDispatcher();
    }
   
    public Test1()
    {
        pushScreen(new TestScreen());
    }
    
} 

 class TestScreen extends MainScreen {
    BtnField bf = new BtnField("hello",FIELD_HCENTER);
    BtnField bf1 = new BtnField("Hi",FIELD_HCENTER);
    BtnField bf2 = new BtnField("bye",FIELD_HCENTER);
    HorizontalFieldManager hfm= new HorizontalFieldManager(FIELD_HCENTER);
    EditField part1;
    LabelField L1;
    public TestScreen() {
        part1 = new EditField(null,null,100,EditField.FILTER_DEFAULT);
        L1 = new LabelField("hello");
        //add(part1);
        add(L1);
        hfm.add(bf);
        hfm.add(bf1);
        hfm.add(bf2);
        add(hfm);
       
    }  
    private class BtnField extends ButtonField implements FieldChangeListener
    {
        public BtnField(String label,long style) 
        {
            super(label,style);
            setChangeListener(this);
        }
        public void fieldChanged(Field field,int context)
        {
            String str= super.getLabel();
            if(str.equals("hello"))
            {
                Dialog.alert("hello");
            } else if (str.equals("Hi")) {
                Dialog.alert("Hi");
            } else if (str.equals("bye")) {
                Dialog.alert("bye");
                System.exit(0);
            }
        }
    }
}
__________________
Thanks
Meenal

Last edited by Meenal : 04-16-2007 at 01:38 AM.
Offline  
Old 04-16-2007, 02:24 AM   #3 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

or some basic code:

ButtonField myButton = new ButtonField("Click me", ButtonField.CONSUME_CLICK);

add(myButton);

myButton.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
Status.show("you pushed the button");
}
});
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Electro PowerPacs Leitz Model 1220 Industrial Xeon Lamp PSU Power Supply PARTS
$49.99
Electro PowerPacs Leitz Model 1220 Industrial Xeon Lamp PSU Power Supply PARTS pictureBio Rad Electrophoresis Cooling Module (Non-CFC)
$39.0
Bio Rad Electrophoresis Cooling Module (Non-CFC) picturePolycom DMA 7000 E16S E16S001 Dell PowerEdge R620 2x GHz Xeon E5-2620 16 GB RAM
$1299.99
Polycom DMA 7000 E16S E16S001 Dell PowerEdge R620 2x GHz Xeon E5-2620 16 GB RAM picturePortwell Single Board Computer B9300324AB18820820 M21 Dual Intel Xeon 2.8GHz SBC
$479.0
Portwell Single Board Computer B9300324AB18820820 M21 Dual Intel Xeon 2.8GHz SBC pictureZebra Technologies 102-801-00000 Series 105SLPlus TT Tabletop Printer
$999.99
Zebra Technologies 102-801-00000 Series 105SLPlus TT Tabletop Printer picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.