Changes

Jump to: navigation, search
Created page with '=== 6. Add elements to Add Screen === 6.1. This application is using a dialog window to add a student.<br/> 6.2. Implement <code>AddCommandHandler</code> by implementing <code>Co…'
=== 6. Add elements to Add Screen ===
6.1. This application is using a dialog window to add a student.<br/>
6.2. Implement <code>AddCommandHandler</code> by implementing <code>CommandHandler</code> as anonymous class:
<pre>
addItem.setCommand(new Command(new CommandHandler() {
public void execute(ReadOnlyCommandMetadata metadata, Object context) {
String[] selections = {"Add","Cancel"};
Dialog addDialog = new Dialog("Add Student", selections, null, 0, null);
EditField inputField1 = new EditField("Student's firstName: ","");
addDialog.add(inputField1);
EditField inputField2 = new EditField("Student's lastName: ","");
addDialog.add(inputField2);
EditField inputField3 = new EditField("Student's email: ","");
addDialog.add(inputField3);

// Display the dialog and add a new element to the list
if(addDialog.doModal() == 0) {
addElementToList(new Student(inputField1.getText(),inputField2.getText(),inputField3.getText()));
}
}
}));
</pre>
6.3. Run the application and select "''Add student''" from the menu:<br/>
[[Image: BB_add.png | 300px ]]]
1
edit

Navigation menu