Time for action – using text fields

Follow these steps to add some fun to our application:

  1. Change your code to add the required text fields just before the line that creates the button instance by adding the highlighted code:
    // ...
    setContent(layout);
            
    final TextField name1 = new TextField("Somebody's name");
    final TextField name2 = new TextField("somebody's name");
    layout.addComponent(name1);
    layout.addComponent(name2);
            
    Button button = new Button("Click Me");
    // ...
  2. Add the business logic in a new method like this:
    public String getFunnyPhrase(String name1, String name2) { String[] verbs = new String[] { "eats", "melts", "breaks", "washes", "sells"}; String[] bodyParts = new String[] { "head", "hands", "waist", "eyes", "elbows"}; return name1 + " ...

Get Vaadin 7 UI Design By Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.