1
edit
Changes
Created page with ' === 5. Add Image to the Menu === 5.1. Open <code>ViewStudentApp</code> class and add menu items inside the constructor.<br/> 5.2 Add add, edit and delete student options to theā¦'
=== 5. Add Image to the Menu ===
5.1. Open <code>ViewStudentApp</code> class and add menu items inside the constructor.<br/>
5.2 Add add, edit and delete student options to the menu and set commands to execute:
<source lang="java">
MyScreen _mainScreen = new MyScreen(this);
MenuItem addItem = new MenuItem(new StringProvider("Add Student"), 200, 2);
adds.setCommand(new Command(new AddCommandHandler()));
_mainScreen.addMenuItem(addItem);
MenuItem editItem = new MenuItem(new StringProvider("Edit Student"), 300, 3);
edit.setCommand(new Command(new EditCommandHandler()));
_mainScreen.addMenuItem(editItem);
MenuItem delete = new MenuItem(new StringProvider("Delete Student"), 400, 4);
delete.setCommand(new Command(new DeleteCommandHandler()));
_mainScreen.addMenuItem(deleteItem);
pushScreen(_mainScreen);
</source>
5.3. Create inner classes to execute all commands:
<source lang="java">
class AddCommandHandler extends CommandHandler
{
public void execute(ReadOnlyCommandMetadata metadata, Object context){
Dialog.alert("Add was selected");
}
}
class EditCommandHandler extends CommandHandler
{
public void execute(ReadOnlyCommandMetadata metadata, Object context){
Dialog.alert("Edit was selected");
}
}
class DeleteCommandHandler extends CommandHandler
{
public void execute(ReadOnlyCommandMetadata metadata, Object context){
Dialog.alert("Delete was selected");
}
}
</source>
5.4. Run the application. Click on the menu you should see the following:<br/>
[[Image: BB_Menu.png | 300px]]<br/>
5.5. Select one of the menu options. The pop-up message should appear:<br/>
[[Image: BB_Menu2.png | 300px]]