BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-16-2008, 06:12 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with my program please

Please Login to Remove!

Hey, i've done a lot of stuff with java in the pass but i'm new in building programs for BlackBerry.
Basically i've been only practicing on the last few days, just to learn and then start my actual program.
The thing is, i got stuck in one problem and i can't solve it, in any way

Here's my code until now(i'll explain what it does after the code):

Quote:

package com.rim.samples.device.spellcheckdemo;

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

class Work extends UiApplication {
public static void main(String[]args) {
Work n = new Work();
n.enterEventDispatcher();
}
Work() {
pushScreen(new WorkScreen());
}
}
class WorkScreen extends MainScreen {

EditField name;

public WorkScreen() {
super();
LabelField title = new LabelField("Program Alpha", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
add(new RichTextField("Hello"));
name = new EditField("Name: ", "");
name.setChangeListener(new EditListener());
add(name);
ButtonField go = new ButtonField("Go!");
go.setChangeListener(new ButtonListener());
RadioButtonGroup rgrp = new RadioButtonGroup();
RadioButtonField radio = new RadioButtonField("Good?", rgrp, true);
RadioButtonField radio2 = new RadioButtonField("Bad?", rgrp, false);
RadioButtonField radio3 = new RadioButtonField("DM", rgrp, false);
add(radio);
add(radio2);
add(radio3);
add(go);
}
public boolean OnClose() {
Dialog.alert("OH NOES");
System.exit(0);
return true;
}
}
final class EditListener implements FieldChangeListener {
Field now;
public void fieldChanged(Field field, int context) {
Field now = field;
}
}
final class ButtonListener implements FieldChangeListener {
Field name;
public ButtonListener() {
}
public void UpdateName(Field n) {
name = n;
}
public void fieldChanged(Field field, int context) {
ButtonField btn = (ButtonField) field;
Status.show("Your name: "+name);
}
}

Sorry if the HTML format destroyed the code :(

but anyways...

like i said, this is a program that would just help me to understand the new stuff, and remember the old java stuff

when you execute it, it rolls like a normal program in this format:

"Hello.
Name:
[o] Good?
[ ] Bad?
[ ] DM
GO!

Name is an EditField where the person can write their name right after the "Name: "
Good bad and DM are a group of radiobuttons inside rgrp
Go! is a normal button.

Until now i got that when you click "Go!" it will appear a message saying "Your name: null".

That because i never found a way that i could check the EditField, since it's in another class...i tryed all the ways i could think in my head, creating a listener for the editfield, to keep track of the actual real EditField, but in the end i could never send it to the Button class, so that the name would appear witht he "Your name: ". this is my first question, if anyone has any idea of how can i make that...

and since i'm here, i'm gonna just ask this other question, that it kinda has to do with the other one
i wanted also to check which of the radiobuttons is true...and make if statements with that inside the Buttonlistener.

If anyone could help me i would appreciate it!
Offline  
Old 07-16-2008, 08:02 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

I'm not sure you need all those field change listeners, since you want the action to take place when the button is pressed I would suggest this: (also read the sticky thread on how to paste formatted code into your posts, probably should read them all really)

Disclaimer: I haven't run this through the compiler, or vetted it for correctness, but you should get the idea.

Code:
package com.rim.samples.device.spellcheckdemo;

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

class Work extends UiApplication {
  public static void main(String[]args) {
    Work n = new Work();
    n.enterEventDispatcher();
  }
  Work() {
    pushScreen(new WorkScreen());
  }
}

class WorkScreen extends MainScreen implements FieldChangeListener {

  EditField name;

  public WorkScreen() {
    super();
    LabelField title = new LabelField("Program Alpha", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
    setTitle(title);
    add(new RichTextField("Hello"));
    name = new EditField("Name: ", "");
    //name.setChangeListener(new EditListener());
    add(name);
    ButtonField go = new ButtonField("Go!");
    go.setChangeListener(new ButtonListener());
    RadioButtonGroup rgrp = new RadioButtonGroup();
    RadioButtonField radio = new RadioButtonField("Good?", rgrp, true);
    RadioButtonField radio2 = new RadioButtonField("Bad?", rgrp, false);
    RadioButtonField radio3 = new RadioButtonField("DM", rgrp, false);
    add(radio);
    add(radio2);
    add(radio3);
    add(go);
  }

  public boolean OnClose() {
    Dialog.alert("OH NOES");
    System.exit(0);
    return true;
    }
  }

  public void fieldChanged(Field field, int context) {
    // probably should do some tests on context, could also test
    // field if class is registered as listener for multiple fields.
    Status.show("Your name: "+name.getText());
  }
}
Offline  
Old 07-17-2008, 09:49 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

wait....
am i supposed to delete the button listener too?
so what's going to recognize when the button is pressed?
Offline  
Old 07-17-2008, 10:26 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

and how did the "fieldChanged" got liked with the "name"?
or the button?
i'm kinda confused right now :( sorry...
could anyone explain it to me? ._.
Offline  
Old 07-17-2008, 10:38 AM   #5 (permalink)
New Member
 
Join Date: Jun 2008
Model: 7290
PIN: N/A
Carrier: Cingular
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

In his example, the Buttonlistener should be "this" since WorkScreen is the one implementing the FieldChangeListener. The WorkScreen itself is going to recognize that the button has been pressed. Also since now name is defined in the same class, you can use the methods provided by EditField.

As for your radio buttons, you can make if/else tree by using the RadioButtonField's isSelected() method, or use your RadioButtonGroup's getSelectedIndex() method to see which one is selected.
Offline  
Old 07-17-2008, 10:46 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you a lot!
you helped me a lot in a little bit of text
i appreciate it
Offline  
Old 07-17-2008, 10:50 AM   #7 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Sorry about that, PaoloLim is right, end of a couple of long days

Glad someone could get you sorted out.
Offline  
Old 07-17-2008, 10:53 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

no, you gave me a push too and that helped me
i just forgot about the "this" thingy
and i was trying to call the same class that was being executed, and off course, i was getting an error...
but thanks for your help too
Offline  
Old 07-18-2008, 10:45 PM   #9 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

You are welcome.
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





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