Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Elements to Main Screen"
Line 1: | Line 1: | ||
=== 3. Add Elements to Main (First) Screen === | === 3. Add Elements to Main (First) Screen === | ||
− | 3.1. Open <code>MyScreen.java</code> class. | + | 3.1. Open <code>MyScreen.java</code> class.<br/> |
− | 3.2. | + | 3.2. Create class <code>Student</code> with the following fields: |
+ | <pre> | ||
+ | private String firstName; | ||
+ | private String lastName; | ||
+ | private String email; | ||
+ | </pre> | ||
+ | 3.3. Add an array in <code>MyScreen</code> class to work with data.<br/> | ||
+ | 3.4. The following elements are added to the <code>MyScreen()</code> constructor. Add a text field: <br/> | ||
+ | <pre> | ||
+ | add(new AutoTextEditField("Student Name: ", "")); | ||
+ | </pre> | ||
+ | 3.5. Add a search button: | ||
+ | <pre> | ||
+ | add(new ButtonField("Search")); | ||
+ | </pre> | ||
+ | 3.6. Add the array of students to the list field: | ||
+ | <pre> | ||
+ | ObjectListField olf = new ObjectListField(); | ||
+ | for (int i=0; i< ls.length; i++) { | ||
+ | olf.insert(i, ls[i].getFirstName() + " " + ls[i].getLastName()); | ||
+ | } | ||
+ | add(olf); | ||
+ | </pre> | ||
+ | 3.7. Add view, add, edit and delete student options to the menu and set commands to execute: | ||
+ | <pre> | ||
+ | MenuItem view = new MenuItem(new StringProvider("View Student"), 100, 1); | ||
+ | view.setCommand(new Command(new ViewCommandHandler())); | ||
+ | addMenuItem(view); | ||
+ | |||
+ | MenuItem adds = new MenuItem(new StringProvider("Add Student"), 200, 2); | ||
+ | adds.setCommand(new Command(new AddCommandHandler())); | ||
+ | addMenuItem(adds); | ||
+ | |||
+ | MenuItem edit = new MenuItem(new StringProvider("Edit Student"), 300, 3); | ||
+ | edit.setCommand(new Command(new EditCommandHandler())); | ||
+ | addMenuItem(edit); | ||
+ | |||
+ | MenuItem delete = new MenuItem(new StringProvider("Edit Student"), 400, 4); | ||
+ | delete.setCommand(new Command(new DeleteCommandHandler())); | ||
+ | addMenuItem(delete); | ||
+ | </pre> | ||
+ | 3.8. Create inner classes to execute all commands: | ||
+ | <pre> | ||
+ | class ViewCommandHandler extends CommandHandler | ||
+ | { | ||
+ | public void execute(ReadOnlyCommandMetadata metadata, Object context){ | ||
+ | Dialog.alert("View was selected"); | ||
+ | } | ||
+ | } | ||
+ | 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"); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | 3.9. |
Revision as of 14:49, 17 March 2011
3. Add Elements to Main (First) Screen
3.1. Open MyScreen.java
class.
3.2. Create class Student
with the following fields:
private String firstName; private String lastName; private String email;
3.3. Add an array in MyScreen
class to work with data.
3.4. The following elements are added to the MyScreen()
constructor. Add a text field:
add(new AutoTextEditField("Student Name: ", ""));
3.5. Add a search button:
add(new ButtonField("Search"));
3.6. Add the array of students to the list field:
ObjectListField olf = new ObjectListField(); for (int i=0; i< ls.length; i++) { olf.insert(i, ls[i].getFirstName() + " " + ls[i].getLastName()); } add(olf);
3.7. Add view, add, edit and delete student options to the menu and set commands to execute:
MenuItem view = new MenuItem(new StringProvider("View Student"), 100, 1); view.setCommand(new Command(new ViewCommandHandler())); addMenuItem(view); MenuItem adds = new MenuItem(new StringProvider("Add Student"), 200, 2); adds.setCommand(new Command(new AddCommandHandler())); addMenuItem(adds); MenuItem edit = new MenuItem(new StringProvider("Edit Student"), 300, 3); edit.setCommand(new Command(new EditCommandHandler())); addMenuItem(edit); MenuItem delete = new MenuItem(new StringProvider("Edit Student"), 400, 4); delete.setCommand(new Command(new DeleteCommandHandler())); addMenuItem(delete);
3.8. Create inner classes to execute all commands:
class ViewCommandHandler extends CommandHandler { public void execute(ReadOnlyCommandMetadata metadata, Object context){ Dialog.alert("View was selected"); } } 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"); } }
3.9.