Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Elements to Main Screen"
Line 10: | Line 10: | ||
3.4. The following elements are added to the <code>MyScreen()</code> constructor. Add a text field: <br/> | 3.4. The following elements are added to the <code>MyScreen()</code> constructor. Add a text field: <br/> | ||
<pre> | <pre> | ||
− | + | AutoTextEditField atf = new AutoTextEditField("Student Name: ", ""); | |
</pre> | </pre> | ||
− | 3.5. Add a search button: | + | 3.5. Set the border and background for the text field: |
+ | <pre> | ||
+ | Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(5, 5, 5, 5), Border.STYLE_SOLID); | ||
+ | Background solidBackground = BackgroundFactory.createSolidBackground(Color.LIGHTSTEELBLUE); | ||
+ | atf.setBorder(roundedBorder); | ||
+ | atf.setBackground(solidBackground); | ||
+ | add(atf); | ||
+ | </pre> | ||
+ | 3.6. Add a search button: | ||
<pre> | <pre> | ||
ButtonField _bf=new ButtonField("Search"); | ButtonField _bf=new ButtonField("Search"); | ||
add(_bf); | add(_bf); | ||
</pre> | </pre> | ||
− | 3. | + | 3.7. Add the array of students to the list field: |
<pre> | <pre> | ||
ObjectListField olf = new ObjectListField(); | ObjectListField olf = new ObjectListField(); | ||
Line 25: | Line 33: | ||
add(olf); | add(olf); | ||
</pre> | </pre> | ||
− | 3. | + | 3.8. Open <code>MyApp</code> class and add menu items inside the constructor. |
− | 3. | + | 3.9 Add view, add, edit and delete student options to the menu and set commands to execute: |
<pre> | <pre> | ||
MyScreen _mainScreen = new MyScreen(); | MyScreen _mainScreen = new MyScreen(); | ||
Line 47: | Line 55: | ||
pushScreen(_mainScreen); | pushScreen(_mainScreen); | ||
</pre> | </pre> | ||
− | 3. | + | 3.10. Create inner classes to execute all commands: |
<pre> | <pre> | ||
class ViewCommandHandler extends CommandHandler | class ViewCommandHandler extends CommandHandler | ||
Line 74: | Line 82: | ||
} | } | ||
</pre> | </pre> | ||
− | 3. | + | 3.11. Now create the all other screen and implement menu commands. |
Revision as of 15:48, 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:
AutoTextEditField atf = new AutoTextEditField("Student Name: ", "");
3.5. Set the border and background for the text field:
Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(5, 5, 5, 5), Border.STYLE_SOLID); Background solidBackground = BackgroundFactory.createSolidBackground(Color.LIGHTSTEELBLUE); atf.setBorder(roundedBorder); atf.setBackground(solidBackground); add(atf);
3.6. Add a search button:
ButtonField _bf=new ButtonField("Search"); add(_bf);
3.7. 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.8. Open MyApp
class and add menu items inside the constructor.
3.9 Add view, add, edit and delete student options to the menu and set commands to execute:
MyScreen _mainScreen = new MyScreen(); MenuItem view = new MenuItem(new StringProvider("View Student"), 100, 1); view.setCommand(new Command(new ViewCommandHandler())); _mainScreen.addMenuItem(view); MenuItem adds = new MenuItem(new StringProvider("Add Student"), 200, 2); adds.setCommand(new Command(new AddCommandHandler())); _mainScreen.addMenuItem(adds); MenuItem edit = new MenuItem(new StringProvider("Edit Student"), 300, 3); edit.setCommand(new Command(new EditCommandHandler())); _mainScreen.addMenuItem(edit); MenuItem delete = new MenuItem(new StringProvider("Delete Student"), 400, 4); delete.setCommand(new Command(new DeleteCommandHandler())); _mainScreen.addMenuItem(delete); pushScreen(_mainScreen);
3.10. 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.11. Now create the all other screen and implement menu commands.