Changes

Jump to: navigation, search
no edit summary
=== 45. Add Elements to View Screen ===45.1. Create new Class <code>ViewScreenInfoScreen</code> that extends <code>MainScreen</code>as inner class in MyScreen:<br/>4 <source lang="java"> private final static class InfoScreen extends MainScreen { InfoScreen(Student student) { //add elements here } } </source>5.2. Set the title: <presource lang="java"> setTitle(student.toString()); </source>5.3. Add the text field: <source lang="Student Infojava"> BasicEditField emailField = new BasicEditField("email: ",student.getEmail(),50,Field.NON_FOCUSABLE); add(emailField); </presource>5.4.3Format this field: <source lang="java"> Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), Border.STYLE_SOLID); Background solidBackground = BackgroundFactory.createSolidBackground(Color.CORAL); emailField.setBorder(roundedBorder); emailField.setBackground(solidBackground); </source>5.5. Override the ,code>close()</code> method: <source lang="java"> public void close() { Dialog.alert("Quit"); super.close(); } </source>5.6. Some mehtods inside the <code>MyScreen</code> should be overriden. <br>In order to show the View screen override the <code>invokeAction()</code> method: <source lang="java"> public boolean invokeAction(int action) { if(action == ACTION_INVOKE) { displayInfoScreen(); return true; } return super.invokeAction(action); } </source>5.7. If enter was hit we want to show the view Screen: <source lang="java"> protected boolean keyChar(char key, int status, int time) { if (key == Characters.ENTER) { displayInfoScreen(); return true; } return super.keyChar(key, status, time); } </source>5.8. Override the <code>onSavePrompt()</code> to suppress the save dialog: <source lang="java"> public boolean onSavePrompt() { return true; } </source>5.9. Create the method to push the view screen into the stack: <source lang="java"> private void displayInfoScreen(){ // Retrieve the selected Country and use it to invoke a new InfoScreen Student student = (Student)_keywordFilterField.getSelectedElement(); if(student!= null) { InfoScreen infoScreen = new InfoScreen(student); _app.pushScreen(infoScreen); } } </source>5.10. Run the application and click on a student:<br/>[[Image: BB_view.png | 300px]]
1
edit

Navigation menu