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 trialchase singhofen
3,811 Pointsi had it correct and then i had to go back and re enter it. now i get 50 syntax errors.
i dont know why when i have to go back i have to answer all the questions over again if i have already answered them they should be simply that.
a simple answer for this is all i asked for. i am trying to get back to where i left off.
package com.example;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class Home extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Group root = new Group();
Button playButton = new Button();
playButton.setOnAction(new EventHandler<ActionEvent>(){
playButton.setOnAction(evt -> System.out.println("Playing!"));
// Add an event handler for playButton
root.getChildren().add(playButton);
primaryStage.setTitle("Boombox");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I'm not sure what questions you're referring to, but the code needed for this challenge is only one line. The button is already created for you. And you had it mostly correct, but then you have some stray curly braces which are causing compiler errors. To be clear, this is not a problem with the challenge and should cause compiler errors with any Java compiler.
But here is the single line you're looking for:
playButton.setOnAction(evt -> System.out.println("Playing!"));
This sets an action on the button that was already created for you and assigns an event that prints out "Playing!" when clicked.
Hope this helps!
chase singhofen
3,811 Pointschase singhofen
3,811 Pointsi had to start fresh from the module. it finally worked for me but i didnt change anything. so idk what happened and i dont want to question it.
im still working on another error in the next question.
i think i need to switch to front end. i think i understand that more