BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-02-2011, 05:41 AM   #1 (permalink)
New Member
 
Join Date: Jun 2011
Model: 9530
PIN: N/A
Carrier: analyst
Posts: 8
Post Thanks: 2
Thanked 0 Times in 0 Posts
Post [HELP] simple get input text

Please Login to Remove!

HI, I'm a newbie in jde programming

I wanto make simple application like this.

I have a basic edit field, it is for get text input from user and a button field.
After we type a text and push button field.
It will appear new screen and display the input.

example:
if user typed: "test one two three four five six"

then user click the button, it will appear new screen like this.

test
one
two
three
four
five

//the first and fourth words at the left at the center of screen
//the second and fifth words at the center of screen
//the third and sixth words at the center of screen

this my code:
/


import net.rim.device.api.system.Bitmap;
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.ui.component.RadioButtonField;

/**
*
*/
class part1 extends UiApplication
{
public static void main(String args[])
{
part1 aplikasi = new part1();
aplikasi.enterEventDispatcher();
}
public part1()
{
pushScreen(new part1Screen());
}
}
final class part1Screen extends MainScreen
{
HorizontalFieldManager _fieldManagerTop;
VerticalFieldManager _fieldManagerMiddle;
HorizontalFieldManager _fieldManagerBottom;
BitmapField _bitmap;
Bitmap _xeditImage;
LabelField _label;
BasicEditField _input;
String _xInput, _textInput;

public part1Screen()
{
super();
LabelField title = new LabelField("TEST", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
_fieldManagerTop = new HorizontalFieldManager();
_fieldManagerMiddle = new VerticalFieldManager();
_fieldManagerBottom = new HorizontalFieldManager();
add(_fieldManagerTop);
add(_fieldManagerMiddle);
_xeditImage = Bitmap.getBitmapResource("xedit.png");
_bitmap = new BitmapField();
_bitmap.setBitmap(_xeditImage);
_fieldManagerTop.add(_bitmap);
_textInput = "";
_xInput = _textInput;



_input = new BasicEditField("Word: ", _xInput);
_fieldManagerMiddle.add(_input);


FieldChangeListener listenerCanada = new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
ButtonField buttonField = (ButtonField) field;
System.out.println("Button pressed: " + buttonField.getLabel());
_textInput = _input.getText();
}
};

ButtonField canadaButton = new ButtonField("Display");
canadaButton.setChangeListener(listenerCanada);
_fieldManagerBottom.add(canadaButton);


}

public void close()
{
Dialog.alert("bye bie");
System.exit(0);
//return true;
super.close();
}

}

Last edited by slametsugih : 06-02-2011 at 06:09 AM. Reason: typo
Offline  
Old 06-02-2011, 07:22 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default Re: [HELP] simple get input text

What is the question or problem?
Offline  
Old 06-02-2011, 07:55 AM   #3 (permalink)
New Member
 
Join Date: Jun 2011
Model: 9530
PIN: N/A
Carrier: analyst
Posts: 8
Post Thanks: 2
Thanked 0 Times in 0 Posts
Default Re: [HELP] simple get input text

Quote:
Originally Posted by Dougsg38p View Post
What is the question or problem?
how to display the input text into new screen?
Offline  
Old 06-02-2011, 08:27 AM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default Re: [HELP] simple get input text

1. Create a new screen class, extending MainScreen.
2. Add a method to the class "addMyData"
3. In the screen implementation, add the "myData" to the screen (some type of TextField, I guess)
4. In your code above, instantiate the new screen and push it when the data is entered and the button is pressed.
Offline  
The Following User Says Thank You to Dougsg38p For This Useful Post:
slametsugih (06-02-2011)
Old 06-02-2011, 09:36 AM   #5 (permalink)
New Member
 
Join Date: Jun 2011
Model: 9530
PIN: N/A
Carrier: analyst
Posts: 8
Post Thanks: 2
Thanked 0 Times in 0 Posts
Default Re: [HELP] simple get input text

Quote:
Originally Posted by Dougsg38p View Post
1. Create a new screen class, extending MainScreen.
2. Add a method to the class "addMyData"
3. In the screen implementation, add the "myData" to the screen (some type of TextField, I guess)
4. In your code above, instantiate the new screen and push it when the data is entered and the button is pressed.
thanks in advance,
so far I can display the input in new screen, but my problem haven't solved yet.
I have to display the input like this.
if input is = "one two three four five six"

then the output in new screen is

the screen:

one----------------------------
--------------two--------------
--------------------------three
four---------------------------
--------------five-------------
----------------------------six

please don't care the "-", i mean one and four on the left,
two and five on the center, three and six on the right side of the screen

so far i have made the method splitter, to split the input.
how to make an array of labelfied to assign each string after its had split and how to place the string in appropriate place, like above.
so how to set position of each labelfield?



thanks before

Last edited by slametsugih : 06-02-2011 at 09:39 AM. Reason: typo
Offline  
Old 06-02-2011, 09:45 AM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default Re: [HELP] simple get input text

Fields are placed by the layout manager.

I would suggest either using the GridFieldManager, or writing your own layout manager.

This is covered in the BB SDK developers guide.
Offline  
The Following User Says Thank You to Dougsg38p For This Useful Post:
slametsugih (06-02-2011)
Old 06-02-2011, 10:36 AM   #7 (permalink)
New Member
 
Join Date: Jun 2011
Model: 9530
PIN: N/A
Carrier: analyst
Posts: 8
Post Thanks: 2
Thanked 0 Times in 0 Posts
Default Re: [HELP] simple get input text

thanks a lot for your reply, but I have solved my problem now.
Code:
/*
 * part1.java
 *
 *  <se7enSky>, 2003-2008
 * Confidential and proprietary.
 */

package latihan.belajar.part1;


import net.rim.device.api.system.Bitmap;
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.ui.component.RadioButtonField;

/**
 * 
 */
class part1 extends UiApplication
{
    public static void main(String args[])
    {
        part1 aplikasi = new part1();
        aplikasi.enterEventDispatcher();
    }
    public part1() 
    {    
        pushScreen(new part1Screen());
    }
} 
final class part1Screen extends MainScreen
{
    HorizontalFieldManager _fieldManagerTop;
    VerticalFieldManager _fieldManagerMiddle;
    HorizontalFieldManager _fieldManagerBottom;
    BitmapField _bitmap;
    Bitmap _canadaImage, _ukImage, _usImage, _xeditImage;
    LabelField _label;
    AutoTextEditField _input;
    String _canadaCapital, _ukCapital, _usCapital, _capital, _xInput, _textInput;
    int displayed = 0;
    
    public part1Screen()
    {
        super();
        LabelField title  = new LabelField("kamus1", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(title);
        
        _fieldManagerTop = new HorizontalFieldManager();
        _fieldManagerMiddle = new VerticalFieldManager();
        _fieldManagerBottom = new HorizontalFieldManager();
        add(_fieldManagerTop);
        add(_fieldManagerMiddle);

        _xeditImage = Bitmap.getBitmapResource("xedit.png");
        _bitmap = new BitmapField();
        _bitmap.setBitmap(_xeditImage);
        _fieldManagerTop.add(_bitmap);
        
        _input = new AutoTextEditField("Word: ", "");
        _fieldManagerMiddle.add(_input);
       
        RadioButtonGroup rbg = new RadioButtonGroup();
        RadioButtonField r1 = new RadioButtonField("English to Indonesia", rbg, true);
        RadioButtonField r2 = new RadioButtonField("Indonesia to English", rbg, false);
        add(r1);
        add(r2);
        add(new SeparatorField());
        add(_fieldManagerBottom);
        
        
        FieldChangeListener listenerCanada = new FieldChangeListener() 
        {
            public void fieldChanged(Field field, int context) 
            {
                
                ButtonField canadaButton = (ButtonField) field;
                //System.out.println("Button pressed: " + canadaButton.getLabel());
                if (field == canadaButton) 
                {
                    UiApplication.getUiApplication().popScreen(part1Screen.this);
                    _label = new LabelField(_input.getText());
                    UiApplication.getUiApplication().pushScreen(new part1Screen2(_input.getText()));
                }
            }
        };
        
         ButtonField canadaButton = new ButtonField("Translate", ButtonField.CONSUME_CLICK);
         canadaButton.setChangeListener(listenerCanada);
         _fieldManagerBottom.add(canadaButton);
    }
}

final class part1Screen2 extends MainScreen  
{      
        VerticalFieldManager _fieldManagerMiddle;
        LabelField _label2;
        
        public part1Screen2(String str)
        {    
            super();
            LabelField title  = new LabelField("result", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            setTitle(title);
            
            //System.out.println(str);
        
            String[] arrString = split(str);
            _label2 = new LabelField();
            
            for (int i=0; i< arrString.length; i++) 
            {
                System.out.println("array element " + i + ": " + arrString[i]);
                
                if(i%3==0)
                    add(new LabelField(""+arrString[i],LabelField.FIELD_LEFT));
                else if(i%3==1)
                    add(new LabelField(""+arrString[i],LabelField.FIELD_HCENTER));
                else if(i%3==2)
                    add(new LabelField(""+arrString[i],LabelField.FIELD_RIGHT));
            }
       }
       
       public static String[] split(String strString) 
       {
            String[] strArray;
            String strDelimiter = " ";
            int iOccurrences = 0;
            int iIndexOfInnerString = 0;
            int iIndexOfDelimiter = 0;
            int iCounter = 0;

            if (strString.startsWith(strDelimiter)) 
            {
                strString = strString.substring(strDelimiter.length());
            }
            if (!strString.endsWith(strDelimiter)) 
            {
                strString += strDelimiter;
            }
            
            while((iIndexOfDelimiter = strString.indexOf(strDelimiter,iIndexOfInnerString)) != -1) 
            {
                iOccurrences += 1;
                iIndexOfInnerString = iIndexOfDelimiter +
                strDelimiter.length();
            }    
            
            strArray = new String[iOccurrences];
    
            iIndexOfInnerString = 0;
            iIndexOfDelimiter = 0;

            while((iIndexOfDelimiter = strString.indexOf(strDelimiter,iIndexOfInnerString)) != -1) 
            {
                strArray[iCounter] = strString.substring(iIndexOfInnerString,iIndexOfDelimiter);

                iIndexOfInnerString = iIndexOfDelimiter +
                strDelimiter.length();
                
                iCounter += 1;
            }

        return strArray;
    }
    
    public void close()
    {   
        Dialog.alert("bye bie");
        System.exit(0);
        //return true;
        super.close();
    }                
}
this absolutely worked, as what I want
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

Similar Threads for: [HELP] simple get input text
Thread Thread Starter Forum Replies Last Post
screen layout-today(current) need2no General 9700 Series Discussion - Bold 2 1 11-29-2010 07:52 PM
Typing Input issue koja General 8900 Series Discussion - Javelin 3 01-08-2009 09:33 AM
HUGE text size when receiving HTML emails! Hanwei General 9500 Series Discussion - Storm 14 12-12-2008 07:20 AM
How to enter text input in canvas for BlacBerry Pearl. ravipogaku Developer Forum 0 11-15-2007 01:43 AM
Nextel Blackberry Users pcbguy BlackBerry Guides 27 11-26-2006 10:02 PM





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