Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application Build a Pomodoro App Properties and Bindings

Abel Cepeda
Abel Cepeda
4,661 Points

${controller.timerText}

for some reason, the text or the numbers will not show in the screen, I follow the video, can someone help me, or explain in detail.

deckey
deckey
14,630 Points

Hi Abel, paste some of your code here, so everyone can take a look. Could be some simple typo, or not, but it's hard to guess what's wrong.

good luck!

3 Answers

deckey
deckey
14,630 Points

I see one typo here:

public String getTimerTex(){
    return mTimerText.get();
}

should be getTimerText()

other than that seems good, post fxml too if it's still not working

Abel Cepeda
Abel Cepeda
4,661 Points

for XML: <Label fx:id="time" text="${controller.timerText}"/> Home.java: public class Home { @FXML private VBox container;

@FXML
private Label title;

private Attempt mCurrentAttempt;
private StringProperty mTimerText;
private Timeline mTimeline;

public Home(){
    mTimerText = new SimpleStringProperty();
    setTimerText(0);
}

public String getTimerTex(){
    return mTimerText.get();
}

public StringProperty timerTextProperty(){
    return mTimerText;
}

public void setTimerText(String timerText){
    mTimerText.set(timerText);
}

public void setTimerText(int remainingSeconds){
    int minutes = remainingSeconds / 60;
    int seconds = remainingSeconds % 60;
    setTimerText(String.format("%02d:%02d", minutes, seconds));
}

private void prepareAttempt(AttemptKind kind){
    clearAttemptStyles();
    mCurrentAttempt = new Attempt(kind, "");
    addAttemptStyle(kind);
    title.setText(kind.getDisplayName());
    setTimerText(mCurrentAttempt.getRemainingSeconds());
    // TODO:csd this is creating multiple time lines we need to fix this!
    mTimeline = new Timeline();
    mTimeline.setCycleCount(kind.getTotalSeconds());
    mTimeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), e -> {
        mCurrentAttempt.tick();
        setTimerText(mCurrentAttempt.getRemainingSeconds());
    }));
}

public void playTimer(){
    mTimeline.play();
}

public void pauseTimer(){
    mTimeline.pause();
}

private void addAttemptStyle(AttemptKind kind){
    container.getStyleClass().add(kind.toString().toLowerCase());
}

private void clearAttemptStyles(){
    for (AttemptKind kind : AttemptKind.values()){
        container.getStyleClass().remove(kind.toString().toLowerCase());
    }
}

public void DEBUG(ActionEvent actionEvent) {
    System.out.println("HI MOM");
}

public void handleRestart(ActionEvent actionEvent){
    prepareAttempt(AttemptKind.FOCUS);
    playTimer();
}

}