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 Design a Better App Controlling Your View

Challenge Task 1 of 1, Build a JavaFX App / Controlling Your View

I can't figure out what I'm missing.

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<VBox fx:controller="com.example.Controller"
    <Text text="Boombox" />
    <Button text="Play"/>
package com.example;

import javafx.event.ActionEvent;

public class Controller {
  @FXML private Button;
  public void handlePlay(ActionEvent event) {
    System.out.println("[MUSIC PLAYING] - Take it from me holmes, parents just don't understand");
package com.example;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("boombox.fxml"));
        primaryStage.setScene(new Scene(root, 300, 275));

    public static void main(String[] args) {

2 Answers

Rob Bridges
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points


In your button XML you need to add an onAction property. Let's say in instance, I wanted to attach a button to my Method.

I'd make it look something like

<Button text="Play" onAction="#myMethod" />

Just be sure to use the right variable that Craig wants you to use in the challenge, and you'll wire that method to take place once the button is clicked.

Thanks for your help Rob.