Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Elements to View Screen"

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

Latest revision as of 11:28, 28 March 2011

5. Add Elements to View Screen

5.1. Create new Class InfoScreen that extends MainScreen as inner class in MyScreen:

  private final static class InfoScreen extends MainScreen {
    InfoScreen(Student student) {
      //add elements here
    }
  }

5.2. Set the title:

  setTitle(student.toString());

5.3. Add the text field:

  BasicEditField emailField = new BasicEditField("email: ",student.getEmail(),50,Field.NON_FOCUSABLE);
  add(emailField);

5.4. Format this field:

  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);

5.5. Override the ,code>close()</code> method:

  public void close() {
      Dialog.alert("Quit");
      super.close();
   }

5.6. Some mehtods inside the MyScreen should be overriden.
In order to show the View screen override the invokeAction() method:

   public boolean invokeAction(int action) {       
        if(action == ACTION_INVOKE) {        
            displayInfoScreen();               
            return true;
        }
           
        return super.invokeAction(action);
    }

5.7. If enter was hit we want to show the view Screen:

   protected boolean keyChar(char key, int status, int time) {
        if (key == Characters.ENTER) {
            displayInfoScreen();          
            return true;    
        }
                    
        return super.keyChar(key, status, time);
    }

5.8. Override the onSavePrompt() to suppress the save dialog:

   public boolean onSavePrompt() {       
        return true;
    }

5.9. Create the method to push the view screen into the stack:

   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); 
        }
    }

5.10. Run the application and click on a student:
BB view.png