0

I am attempting to make my first GUI in JavaFX. This is what I've done so far:

Main:

    package ZVCVolkel_GUI;

    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 {

        @Override
        public void start(Stage primaryStage) throws Exception{
            Parent root = FXMLLoader.load(getClass().getResource("LoginScreen.fxml"));
            primaryStage.setTitle("Zweegvliegclub Volkel");
            primaryStage.setScene(new Scene(root, 322.0, 182.0));
            primaryStage.show();
        }

        public static void main(String[] args) {
            launch(args);
        }
    }

Controller:

    package ZVCVolkel_GUI;


    import com.jfoenix.controls.JFXButton;
    import com.jfoenix.controls.JFXPasswordField;
    import com.jfoenix.controls.JFXTextField;
    import javafx.fxml.FXML;

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

    public class Controller {

        @FXML
        private JFXTextField username;

        @FXML
        private JFXPasswordField password;

        @FXML
        private JFXButton login;

        @FXML
        void makeLogin(ActionEvent event){
            String user = username.getText();
            String pass = password.getText();
            if(user.equals("Admingeb") && pass.equals("Adminww")){
                System.out.println("Welcome");
            }else{
                System.out.println("Access denied");
            }
        }
    }

FXML file

  <?import com.jfoenix.controls.JFXButton?>
  <?import com.jfoenix.controls.JFXPasswordField?>
  <?import com.jfoenix.controls.JFXTextField?>
  <?import javafx.scene.control.Label?>
  <?import javafx.scene.layout.AnchorPane?>
  <?import javafx.scene.text.Font?>

  <AnchorPane prefHeight="182.0" prefWidth="322.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ZVCVolkel_GUI.Controller">
     <children>
        <Label layoutX="79.0" layoutY="14.0" text="Inloggen bij ZVC Volkel">
           <font>
              <Font name="System Bold" size="15.0" />
           </font>
        </Label>
        <JFXButton fx:id="login" blendMode="SRC_ATOP" layoutX="128.0" layoutY="132.0" mnemonicParsing="false" onAction="#makeLogin" text="Inloggen">
           <font>
              <Font name="System Bold" size="12.0" />
           </font>
        </JFXButton>
        <JFXPasswordField fx:id="password" layoutX="94.0" layoutY="79.0" promptText="Wachtwoord" />
        <JFXTextField fx:id="username" layoutX="94.0" layoutY="54.0" promptText="Gebruikersnaam" />
     </children>
  </AnchorPane>

Now when I try to execute it I get a error saying the onAction on my JFXButton 'Cannot resolve symbol'. When I remove the onAction it works fine but I really need it in order to have a useful program. Anyone has a idea why my onAction is not working?

M. le Rutte
  • 3,525
  • 3
  • 18
  • 31
MrEmper
  • 225
  • 1
  • 4
  • 18

1 Answers1

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

that's an FX application, and you're trying to use awt. Change to FX implementation like this:

import javafx.event.ActionEvent;

it should help

Martin P
  • 114
  • 4