0

I am trying to get some practice in with javaFX, and I just wanted to see if I could get a simple button to be created and prepared with a setOnAction enabled. However, the btn does not have the .setText method aand the EventHandler gives an error on ActionEvent saying that ActionEvent is not bound and should extend Event.

I am following countless tutorials and this should be what everyone is doing for their buttonsetup, but it is falling apart. I am using 1.7_45, so JavaFX is supported. I also enabled the JavaFX support plugin in IDEA.

 //package ;
import javafx.*;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class OptionsToggleMenu  {



public OptionsToggleMenu() {
}

 public void launch(String... args){

 }

 @Override
public void start(Stage primaryStage) {

    primaryStage.setTitle("Hello World!");
    final Button btn = new Button();
     btn.setText("hello world");


   //btn.setText("Say 'Hello World'");

    btn.setOnAction(new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent e) {
            btn.setText("changed");
        }
    });
 }

}

Jayizzle
  • 532
  • 1
  • 6
  • 24
  • Please show the whole class, including imports. – James_D Feb 23 '16 at 15:04
  • 1
    You are using `java.awt.Button` and `java.awt.ActionEvent` instead of the JavaFX classes. Remove all the awt and swing imports. – James_D Feb 23 '16 at 15:09
  • 1
    Your button isn't added to the scene pls check oracle hello world before asking https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm – user43968 Feb 23 '16 at 15:10

1 Answers1

1

You are mixing javafx and swing - you will need to correct your imports.

purring pigeon
  • 4,141
  • 5
  • 35
  • 68