Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Adds solution for Task 1
Browse files Browse the repository at this point in the history
Also updates a To Do in Task 1
  • Loading branch information
Fabian Kerzmann committed Nov 12, 2023
1 parent f4ae9d8 commit 1f89506
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Button createButton() {

/**
* TODO 4.1: Add a method that returns a new green button (hint: change the property "background-color")
* TODO 4.2: Clicking on the button should navigate to the next task (Task2)
* TODO 4.2: Clicking on the button should navigate to the next task ("/task2")
* (Dont forget to add the button to the layout)
*/

Expand Down
29 changes: 17 additions & 12 deletions vaadin-demo/src/main/java/com/example/esde/views/task1/Task1.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.esde.views.task1;

import com.example.esde.views.MainLayout;
import com.example.esde.views.task2.Task2;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
Expand All @@ -19,22 +18,20 @@ public class Task1 extends VerticalLayout {
private H2 header;
private TextField textfield;
private Button button;
private Button successButton;

public Task1() {
header = createHeader();
button = createButton();
successButton = createSuccessButton();
textfield = null;
textfield = createTextfield();

add(header, button, successButton);
add(header, textfield, button, createGreenButton());
}

/**
* TODO 1: Change the header to whatever you would like it to show
*/
private H2 createHeader() {
H2 header = new H2("Replace me");
H2 header = new H2("Some text");

return header;
}
Expand All @@ -44,8 +41,10 @@ private H2 createHeader() {
* TODO 2.2: Add this function into the constructor and put the object also in the "add(...)" function
*/
private TextField createTextfield() {
TextField textField = new TextField();
textField.setLabel("Your Name");

throw new UnsupportedOperationException("This function is not implemented yet :(");
return textField;
}

/**
Expand All @@ -54,6 +53,10 @@ private TextField createTextfield() {
private Button createButton() {
Button button = new Button();
button.setText("Update header");
button.addClickListener(buttonClickEvent -> {
String text = this.textfield.getValue();
this.header.setText("Hello " + text + "!");
});

return button;
}
Expand All @@ -63,15 +66,17 @@ private Button createButton() {
* TODO 4.2: Clicking on the button should navigate to the next task (Task2)
* (Dont forget to add the button to the layout)
*/
private Button createSuccessButton() {
private Button createGreenButton() {
Button button = new Button();
button.setText("Next Task");
button.getStyle().set("background-color","green");
button.addClickListener(buttonClickEvent -> {
getUI().ifPresent(ui -> ui.navigate(Task2.class));
button.getStyle().set("background-color", "green");
button.addClickListener(event -> {
getUI().ifPresent(ui -> {
ui.navigate("task2");
});
});

return button;
}


}

0 comments on commit 1f89506

Please sign in to comment.