java.lang.Object
com.currencycalc.currencycalculatorjavafx.MainController

public class MainController extends Object
The controller class for the Currency Calculator JavaFX application. This class manages user interactions, handles input validation, and processes currency conversions using data fetched from the FreeCurrencyAPI.
Version:
1.0.0
Autor:
Tim Platzer
  • Felddetails

    • convertButton

      private javafx.scene.control.Button convertButton
      The button that triggers the currency conversion process. When clicked, it validates the input, fetches exchange rates, and displays the converted amount.
    • targetCurrencyDropdown

      private javafx.scene.control.ChoiceBox<String> targetCurrencyDropdown
      The dropdown menu for selecting the target currency. This allows users to choose the currency into which they want to convert the source amount.
    • sourceCurrencyDropdown

      private javafx.scene.control.ChoiceBox<String> sourceCurrencyDropdown
      The dropdown menu for selecting the source currency. This allows users to choose the currency from which they want to convert the amount.
    • amountInputField

      private javafx.scene.control.TextField amountInputField
      The input field where the user enters the amount to be converted. The value is validated to ensure it is a numeric input and supports both dots and commas as decimal separators.
    • convertedAmountField

      private javafx.scene.control.TextField convertedAmountField
      The output field where the converted amount is displayed. After the conversion process is completed, the result is formatted to two decimal places and shown here.
    • currencyClient

      private final CurrencyClient currencyClient
      The CurrencyClient instance responsible for communicating with the FreeCurrencyAPI. This client is used to fetch real-time exchange rate data.
    • currencyMap

      private final Map<String,String> currencyMap
      A map of currency codes to their corresponding full names. This map is used to populate dropdown menus with user-friendly currency names while maintaining the ability to work with currency codes internally.

      Example:

      • "AUD": "Australian Dollar"
      • "EUR": "Euro"
      • "USD": "US Dollar"

      The map is implemented as a LinkedHashMap to preserve the order of insertion.

  • Konstruktordetails

    • MainController

      public MainController()
  • Methodendetails

    • initialize

      public void initialize()
      Initializes the controller. Populates the dropdown menus with currency names, sets up input validation, and configures button states.
    • convert

      public void convert() throws IOException, InterruptedException
      Handles the conversion of the entered amount from the source currency to the target currency.
      Löst aus:
      IOException - If an error occurs during the API request.
      InterruptedException - If the request is interrupted.
    • getCurrencyRate

      private Double getCurrencyRate(Data data, String currency)
      Retrieves the exchange rate for a specific currency using reflection.
      Parameter:
      data - The Data object containing all exchange rates.
      currency - The currency code (e.g., "USD").
      Gibt zurück:
      The exchange rate for the given currency, or null if not found.
    • getCurrencyCode

      private String getCurrencyCode(String currencyName)
      Retrieves the currency code (e.g., "USD") for a given currency name.
      Parameter:
      currencyName - The full name of the currency (e.g., "US Dollar").
      Gibt zurück:
      The currency code, or null if not found.
    • getTargetCurrencyDropdown

      public javafx.scene.control.ChoiceBox<String> getTargetCurrencyDropdown()
      Retrieves the target currency dropdown.
      Gibt zurück:
      The ChoiceBox for selecting the target currency.
    • getSourceCurrencyDropdown

      public javafx.scene.control.ChoiceBox<String> getSourceCurrencyDropdown()
      Retrieves the source currency dropdown.
      Gibt zurück:
      The ChoiceBox for selecting the source currency.
    • getAmountInputField

      public javafx.scene.control.TextField getAmountInputField()
      Retrieves the input field for the amount to be converted.
      Gibt zurück:
      The TextField for entering the amount.
    • getConvertedAmountField

      public javafx.scene.control.TextField getConvertedAmountField()
      Retrieves the output field for the converted amount.
      Gibt zurück:
      The TextField displaying the converted amount.
    • getCurrencyClient

      public CurrencyClient getCurrencyClient()
      Retrieves the CurrencyClient for API communication.
      Gibt zurück:
      The CurrencyClient instance.
    • getConvertButton

      public javafx.scene.control.Button getConvertButton()
      Retrieves the convert button.
      Gibt zurück:
      The Button used to trigger the conversion.
    • getCurrencyMap

      public Map<String,String> getCurrencyMap()
      Retrieves the map of currency codes and names.
      Gibt zurück:
      A Map containing currency codes as keys and names as values.