HelloApplication.java
package com.example.demo1;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;


import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HelloApplication extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("DocDuck Maintenance Tool");

        // Set application icon
        try {
            Image icon = new Image(getClass().getResourceAsStream("/images/docduckicon.png"));
            primaryStage.getIcons().add(icon);
        } catch (NullPointerException e) {
            System.err.println("Error loading icon: " + e.getMessage());
        }

        BorderPane root = new BorderPane();
        root.getStyleClass().add("background-panel"); // Add background-panel class
        root.getStyleClass().add("root"); // Add root class for consistency

        Font.loadFont(getClass().getResourceAsStream("/fonts/Inter.ttf"), 10);

        VBox loginForm = createLoginForm();
        root.setCenter(loginForm);

        Scene scene = new Scene(root, 600, 600);

        // Link the CSS file, handling potential NullPointerException
        String cssFile = getClass().getResource("/style.css").toExternalForm();
        if (cssFile != null) {
            scene.getStylesheets().add(cssFile);
        } else {
            System.err.println("CSS file not found!");
        }

        primaryStage.setScene(scene);

        // Set minimum window size
        primaryStage.setMinWidth(600);
        primaryStage.setMinHeight(600);

        // Set maximum window size based on the native screen size
        primaryStage.setMaxWidth(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width);
        primaryStage.setMaxHeight(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height);

        // Adjust the size dynamically based on the window size
        scene.widthProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) {
                // Update your layout or content based on the new width
                loginForm.setPrefWidth(newSceneWidth.doubleValue());
            }
        });

        scene.heightProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
                // Update your layout or content based on the new height
                loginForm.setPrefHeight(newSceneHeight.doubleValue());
            }
        });

        primaryStage.show();
    }

    private VBox createLoginForm() {
        VBox vbox = new VBox(10); // Set spacing between elements
        vbox.setAlignment(Pos.CENTER); // Center content vertically and horizontally

        // Username
        TextField usernameField = new TextField();
        usernameField.setPromptText("Username");
        usernameField.getStyleClass().add("text-field");

        // Password
        PasswordField passwordField = new PasswordField();
        passwordField.setPromptText("Password");
        passwordField.getStyleClass().add("password-field");

        // Hyperlink for "Forgot Password"
        Hyperlink forgotPasswordLink = new Hyperlink("Forgot Password?");
        forgotPasswordLink.getStyleClass().add("forgot-password-link");

        // Add event handler to open the link in the system browser
        forgotPasswordLink.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                openLink("https://docduck.000webhostapp.com");
            }
        });

        // Image Placeholder
        try {
            // You need to replace 'your_image_path.png' with the actual path to your image file.
            Image image = new Image(getClass().getResourceAsStream("/images/dockducklogo.png"));
            javafx.scene.image.ImageView imageView = new javafx.scene.image.ImageView(image);
            imageView.setFitWidth(529); // Set the desired width
            imageView.setFitHeight(277); // Set the desired height

            vbox.getChildren().add(imageView);
        } catch (NullPointerException e) {
            System.err.println("Error loading image: " + e.getMessage());
        }

        vbox.getChildren().addAll(usernameField, passwordField, forgotPasswordLink);

        // Button for "Sign Up for Business"
        javafx.scene.control.Button signUpButton = new javafx.scene.control.Button("Sign Up for Business");
        signUpButton.getStyleClass().add("sign-up-button");

        vbox.getChildren().addAll(new javafx.scene.layout.Region(), signUpButton); // Add Region for spacing

        // Add key event handler for Enter key on password field
        passwordField.setOnKeyPressed(new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                if (event.getCode() == KeyCode.ENTER) {
                    // Clear the screen or perform the desired action
                    vbox.getChildren().clear();
                }
            }
        });

        return vbox;
    }

    // Method to open a link in the system's preferred browser
    private void openLink(String link) {
        try {
            Desktop.getDesktop().browse(new URI(link));
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
}