Hello everbody,
I tried some stuff out used as basement the HelloWorld application. Because I am a beginner. What I tried to do it that you can enter your name hit "Check the Name!" and he should do if statements to give back messages. But something is going wrong I allways get the else never the if even if I am 100% sure that I typed it correct.
Code:
/**
* 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.*;
/*
* 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
{
private EditField _edtField;
private String name;
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);
_edtField = new EditField();
//add the text "Hello World!" to the screen
add(new RichTextField("Ihr Name? / Your Name?"));
add(_edtField);
}
//override the onClose() method to display a dialog box to the user
//with "Goodbye!" when the application is closed
public boolean onClose()
{
Dialog.alert("Bye!Bye!");
System.exit(0);
return true;
}
private MenuItem _closeItem = new MenuItem("Close", 200000, 10) {
public void run()
{
onClose();
}
};
private MenuItem _viewItem = new MenuItem("Check the Name!", 110, 10) {
public void run() {
//store the selected city in a variable
name = _edtField.getText();
//display a new screen with information about the
//selected city
if (name == "test")
{
Dialog.alert("test was entered");
}
else if (name == "blabla")
{
Dialog.alert("blabla was entered");
}
else
{
Dialog.alert("!"+name+"!");
}
}
};
//Menü erstellen
protected void makeMenu( Menu menu, int instance )
{
menu.add(_viewItem);
menu.add(_closeItem);
}
} Thanks for your help,
Yves