This is my first attempt at development for the BB storm, and I'm using JDE 4.7.
I started with an Hello World application I found and I modified it to add a simple button that says RED. When clicked I wanted the screen background to turn RED and change the button to say BLUE, when that is clicked it turns BLUE and changes the button back to RED again.
I implement this using a standard ButtonField listener (which I call bhandler in my code). The program kind of works, with the only weird effect on the simulator being that when I click on the button, the background color does change but a small menu appears. Anyone else seen this menu issue? I'm not expecting to see a menu and I haven't coded anything to ask for a menu to appear when I click this button.
Here is my source code. The handler is in bold text. Any answers as to why I see a menu would be most appreciated.....thanks.
/**
* HelloWorld.java
* Copyright (C) 2001-2003 Research In Motion Limited. All rights reserved.
*/
package com.rim.samples.helloworld;
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.*;
import net.rim.device.api.ui.decor.*;
/*
* BlackBerry applications that provide a user interface
* must extend UiApplication.
*/
public class HelloWorld extends UiApplication
{
public static void main(String[] args)
{
//create a new instance of the application
//and start the application on the event thread
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
}
public HelloWorld()
{
//display a new screen
pushScreen(new HelloWorldScreen());
}
}
//create a new screen that extends MainScreen, which provides
//default standard behavior for BlackBerry applications
final class HelloWorldScreen extends MainScreen
{
public HelloWorldScreen()
{
//invoke the MainScreen constructor
super();
//add a title to the screen
LabelField title = new LabelField("HelloWorld Sample", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
setTitle(title);
//add the text "Hello World!" to the screen
add(new RichTextField("Hello World!"));
// First define button handler
FieldChangeListener bhandler = new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
ButtonField buttonField = (ButtonField) field;
if (buttonField.getLabel() == "RED")
{
Background newback = BackgroundFactory.createSolidBackground(Color.RED);
getMainManager().setBackground(newback);
buttonField.setLabel("BLUE");
}
else
{
Background newback = BackgroundFactory.createSolidBackground(Color.BLUE);
getMainManager().setBackground(newback);
buttonField.setLabel("RED");
}
}
}; // Define button itself to use handler above, this one called RED
ButtonField buttonField = new ButtonField("RED"); // Create RED button
buttonField.setChangeListener(bhandler);
// Set up button handler defined above
add(buttonField); // Add the button to the screen.
}
//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;
}
}