to tentando usar o java fx no eclipse, to acostumado com o net beans. queria trocar a imagem quando apertar no botão, mas ta dando erro alguém me ajuda.
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
AnchorPane root = (AnchorPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
________________________________________
package application;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class SampleController implements Initializable {
@FXML
private Label Lbl_Label;
@FXML
private ImageView Iml_Imagem;
@FXML
private Button Btn_Botao;
@FXML
void Acao_botao(ActionEvent event) {
Lbl_Label.setText("Texto trocado!");
Image image = new Image("res/imagem2.gif");
Iml_Imagem.setImage(image);
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="262.0" prefWidth="565.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SampleController">
<children>
<Button fx:id="Btn_Botao" layoutX="365.0" layoutY="26.0" mnemonicParsing="false" onAction="#Acao_botao" prefHeight="85.0" prefWidth="181.0" text="Trocar">
<font>
<Font size="35.0" />
</font>
</Button>
<ImageView fx:id="Iml_Imagem" fitHeight="150.0" fitWidth="200.0" layoutX="79.0" layoutY="69.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../../Desktop/yuri-kof13-crouch-stance.gif" />
</image>
</ImageView>
<Label fx:id="Lbl_Label" alignment="BASELINE_CENTER" layoutX="351.0" layoutY="168.0" prefHeight="63.0" prefWidth="218.0" text="Troque a imagem!">
<font>
<Font size="22.0" />
</font>
</Label>
</children>
</AnchorPane>