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

LAMBDA LS SUTTER INSTRUMENT COMPANY XEON ARC LAMP W/ FILTER
$1300.0
 LAMBDA LS SUTTER INSTRUMENT COMPANY XEON ARC LAMP W/ FILTER pictureNew HP Proliant DL380 Gen4/ML370 Server Intel Xeon Processor 311584-B21
$56.99
New HP Proliant DL380 Gen4/ML370 Server Intel Xeon Processor 311584-B21 pictureAvigilon Video Survillance Server Xeon E5506 Quad Core 2.13Ghz (6) 2TB HD 16Gb.
$459.99
Avigilon Video Survillance Server Xeon E5506 Quad Core 2.13Ghz (6) 2TB HD 16Gb.  pictureEnlight EN-470MP 470W Dual-Fan Control PC/Xeon Server Power Supply (D1)
$45.0
Enlight EN-470MP 470W Dual-Fan Control PC/Xeon Server Power Supply         (D1) pictureSet of 2 HP 307103-001 2.8GHz 2800DP XEON CPU with Heat Sink
$24.0
Set of 2 HP  307103-001 2.8GHz 2800DP XEON CPU with Heat Sink picture






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