Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
cubyn9x
Posts: 21
Registered: ‎06-14-2012
My Device: 9900
My Carrier: vodafone

Help me.........give control to the application's menu

I want a control about the application's menu bar. What should I do?

This is the code AboutScreen.java

 

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.system.ApplicationDescriptor;

/**
* PopupScreen that displays information about the application
*/


final class AboutScreen extends PopupScreen
{
/**
* Constructor.
*/
AboutScreen()
{
super(new VerticalFieldManager());
ApplicationDescriptor appDesc = ApplicationDescriptor.currentApplicationDescriptor();
add(new LabelField(" MyBrowser Ver. " + appDesc.getVersion()));
add(new SeparatorField());
add(new LabelField(" Developed by Keeper© 2010\n louis.keeper[MENTION=362321]Gmail.Com[/MENTION]\n http://www.tinhte.vn")); // Nội dung
add(new LabelField(""));
}


/**
* Overrides the default. Closes the popup screen when the Escape key is pressed.
*
* @see net.rim.device.api.ui.Screen#keyChar(char,int,int)
*/
public boolean keyChar(char c, int status, int time)
{
if (c == Characters.ESCAPE) 
{
close();
return true;
}

return super.keyChar(c, status, time);
}

}

 

////This is the code UiScreen.java

 

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.command.*;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.util.StringProvider;

public final class UiScreen extends MainScreen
{

EditField username;

PasswordEditField password;

ObjectChoiceField domain;

ButtonField btnClear;

ButtonField btnLogin;

LoginCommandHandler loginHandler = new LoginCommandHandler();
ClearCommandHandler clearHandler = new ClearCommandHandler();

public UiScreen()
{

Bitmap logo = Bitmap.getBitmapResource("iconvn.png");
BitmapField bmpField = new BitmapField(logo, Field.FIELD_HCENTER);
add(bmpField);

add(new SeparatorField());

username = new EditField("Tên đăng nhập: ", "");
password = new PasswordEditField("Mật khẩu: ", "");
add(username);
add(password);

domain = new ObjectChoiceField("Địa điểm: ",new String[]{"Nhà riêng","Văn phòng"} );
add(domain);

CheckboxField chkRemember = new CheckboxField("Ghi nhớ mật khẩu", true);
add(chkRemember);

add(new SeparatorField());

btnClear = new ButtonField("Xóa", ButtonField.CONSUME_CLICK);
btnLogin = new ButtonField("Đăng nhập", ButtonField.CONSUME_CLICK );

HorizontalFieldManager buttonManager = new HorizontalFieldManager(Field.FIELD_RIGHT);
add(buttonManager);
buttonManager.add(btnClear);
buttonManager.add(btnLogin);

btnClear.setCommand(new Command(clearHandler));
btnLogin.setCommand(new Command(loginHandler));

setTitle("Thông tin");

}

public void clearText() {
username.setText("");
password.setText("");
}

public void login() {
if (username.getTextLength() == 0 || password.getTextLength() == 0) {
Dialog.alert("Bạn phải nhập tên đăng nhập và mật khẩu");
}
else {
UiApp.getUiApplication().pushScreen(new Album());
}

}

protected void makeMenu(Menu menu, int instance) {

super.makeMenu(menu, instance);

MenuItem loginMenu = new MenuItem(new StringProvider("Đăng nhập"), 20, 10);
loginMenu.setCommand(new Command(loginHandler));
menu.add(loginMenu);

MenuItem clearMenu = new MenuItem(new StringProvider("Xóa"), 20, 10);
clearMenu.setCommand(new Command(clearHandler));
menu.add(clearMenu);
}

class LoginCommandHandler extends CommandHandler{
public void execute(ReadOnlyCommandMetadata metedata, Object context){
login();
}
}
class ClearCommandHandler extends CommandHandler{
public void execute(ReadOnlyCommandMetadata metedata, Object context){
clearText();
}

}
}

 

Help me

Please use plain text.