BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-16-2008, 05:12 PM   #1
Aiwa
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
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, 07:02 PM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
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, 08:49 AM   #3
Aiwa
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
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, 09:26 AM   #4
Aiwa
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
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, 09:38 AM   #5
PaoloLim
New Member
 
Join Date: Jun 2008
Model: 7290
PIN: N/A
Carrier: Cingular
Posts: 14
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, 09:46 AM   #6
Aiwa
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
Default

thank you a lot!
you helped me a lot in a little bit of text
i appreciate it
Offline  
Old 07-17-2008, 09:50 AM   #7
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
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, 09:53 AM   #8
Aiwa
Thumbs Must Hurt
 
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
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, 09:45 PM   #9
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

You are welcome.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


OEM Dell XPS 8910 8920 8930 Alienware Aurora R5 R6 R7 Front Cooling Fan 7M0F5 picture

OEM Dell XPS 8910 8920 8930 Alienware Aurora R5 R6 R7 Front Cooling Fan 7M0F5

$13.81



New Genuine Dell OEM G Series G5 5590 Heatsink Assembly 35YK5 035YK5 1RGDW picture

New Genuine Dell OEM G Series G5 5590 Heatsink Assembly 35YK5 035YK5 1RGDW

$10.99



Dell OEM Latitude Rugged Extreme 7404 GPS Antenna Junction Cable Cable KMX0M picture

Dell OEM Latitude Rugged Extreme 7404 GPS Antenna Junction Cable Cable KMX0M

$2.95



Dell OEM Latitude Rugged Extreme 7404 Docking Connector Circuit Board picture

Dell OEM Latitude Rugged Extreme 7404 Docking Connector Circuit Board

$14.95



NEW DELL OEM REPLACEMENT PROJECTOR LAMP FOR 4220 4320 GENUINE ORIGINAL  picture

NEW DELL OEM REPLACEMENT PROJECTOR LAMP FOR 4220 4320 GENUINE ORIGINAL

$198.22



DELL 330-6581 3306581 725-10229 OEM LAMP FOR 1510X 1610HD 1610X  - Made By DELL picture

DELL 330-6581 3306581 725-10229 OEM LAMP FOR 1510X 1610HD 1610X - Made By DELL

$39.98







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