BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-29-2011, 08:51 PM   #1
alsaadi
New Member
 
Join Date: Jun 2011
Model: 9800
PIN: N/A
Carrier: carrier?
Posts: 1
Unhappy please help me i cannot even make a buttonlistener properly :(

Please Login to Remove!

hello i am a new programming student and i studied my first course for java so i though i will try to do something for blackberry but it turns out its not that east

please help me i am still learning here and this is my code

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.*;

/*
* BlackBerry applications that provide a user interface
* must extend UiApplication.
*/
public class TempConverter extends UiApplication
{
public static void main(String[] args)
{
//create a new instance of the application
//and start the application on the event thread
TempConverter theApp = new TempConverter();
theApp.enterEventDispatcher();
}

public TempConverter()
{
//display a new screen
pushScreen(new TempConverterScreen());
}
}

//create a new screen that extends MainScreen, which provides
//default standard behavior for BlackBerry applications
final class TempConverterScreen extends MainScreen
{
public TempConverterScreen()
{
//invoke the MainScreen constructor
super();

//add a title to the screen
LabelField title = new LabelField("welcome to tempConverter",
LabelField.FIELD_HCENTER | LabelField.USE_ALL_WIDTH);
setTitle(title);

add(new SeparatorField()); // to add a Separator

//add the text "Hello World!" to the screen
LabelField tempInsert = new LabelField("write temp in C", 0, -1, Field.FIELD_HCENTER); // declared a label and wrote within it
Font fnt = this.getFont().derive(Font.BOLD | Font.ITALIC| Font.ARABIC_SCRIPT); //to set font specification along with arabic script
tempInsert.setFont(fnt); //affix the font to the label tempInsert
add(tempInsert); // add tempInsert to the screen

EditField c = new EditField("temperature:", "");
add(c);

ButtonField submit = new ButtonField("result");

submit.setChangeListener(FieldChangeListener(liste ner));

add(submit);

float g = getNumber(c);
float h = calculate(g);

class ButtonListener implements FieldChangeListener {
public void fieldChanged(Field field, int context) {
ButtonField btn = (ButtonField) field;
Status.show("" + h );
}
}

}
final public Float getNumber(EditField field) {
float floatFromField = Float.parseFloat(field.getText());
Float number = new Float(floatFromField);
return number;
}

final public float calculate(float x){

float r = (x*(9/5))+32;
return r;

}




//override the onClose() method to display a dialog box to the user
//with "Goodbye!" when the application is closed
public boolean onClose()
{
Dialog.alert("goodbye!");
System.exit(0);
return true;
}
}



i am getting 3 errors

C:\Program Files\Research In Motion\BlackBerry JDE 6.0.0\bin\TempConverter.java:54: error: cannot find symbol
submit.setChangeListener(FieldChangeListener(liste ner));

C:\Program Files\Research In Motion\BlackBerry JDE 6.0.0\bin\TempConverter.java:58: error: incompatible types
float g = getNumber(c);

C:\Program Files\Research In Motion\BlackBerry JDE 6.0.0\bin\TempConverter.java:64: error: local variable h is accessed from within inner class; needs to be declared final
Status.show("the temp in F" + h );
Offline  
Old 06-30-2011, 07:39 AM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: please help me i cannot even make a buttonlistener properly :(

Please read the sticky thread about posting code. The lump you've posted is very difficult to read. Properly formatted code is easier to debug.

A FieldChangeListener is an interface not a class. You can't call the constructor like: FieldChangeListener(listener)

Float and float are not the same type. A Float is a Class, a float is a scalar.

Declare h as final and read about the java final keyword.
__________________
My other Blackberry is a PlayBook.
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

Similar Threads for: please help me i cannot even make a buttonlistener properly :(
Thread Thread Starter Forum Replies Last Post
Help Help Help Help With Themes 1llest03 BlackBerry Help 6 02-10-2011 01:39 PM
International warranty - please help vesava General BlackBerry Discussion 1 01-30-2011 07:38 AM
Hardware problem - any help will be appreciate vesava BlackBerry Help 1 01-30-2011 07:37 AM
International warranty - help vesava General 9000 Series Discussion - Bold 2 01-30-2011 07:35 AM
I got a bb 8320 i cant make phonecalls though, HELP! orli General 8300 Series Discussion - Curve 2 10-18-2008 06:12 PM


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

$14.63



NEW VESA Adapter Plate for Dell E-Series Monitor - OEM picture

NEW VESA Adapter Plate for Dell E-Series Monitor - OEM

$8.50



Dell OEM Latitude Rugged Extreme 7404 Left and Right Mouse Buttons 00008 picture

Dell OEM Latitude Rugged Extreme 7404 Left and Right Mouse Buttons 00008

$5.95



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 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



Dell 2400MP Audio Video Computer Projector OEM Lamp Part No: 0CF900 picture

Dell 2400MP Audio Video Computer Projector OEM Lamp Part No: 0CF900

$109.95







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