Klasse MainController
java.lang.Object
com.currencycalc.currencycalculatorjavafx.MainController
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
-
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprivate javafx.scene.control.TextField
The input field where the user enters the amount to be converted.private javafx.scene.control.Button
The button that triggers the currency conversion process.private javafx.scene.control.TextField
The output field where the converted amount is displayed.private final CurrencyClient
TheCurrencyClient
instance responsible for communicating with the FreeCurrencyAPI.A map of currency codes to their corresponding full names.private javafx.scene.control.ChoiceBox
<String> The dropdown menu for selecting the source currency.private javafx.scene.control.ChoiceBox
<String> The dropdown menu for selecting the target currency. -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
convert()
Handles the conversion of the entered amount from the source currency to the target currency.javafx.scene.control.TextField
Retrieves the input field for the amount to be converted.javafx.scene.control.Button
Retrieves the convert button.javafx.scene.control.TextField
Retrieves the output field for the converted amount.Retrieves theCurrencyClient
for API communication.private String
getCurrencyCode
(String currencyName) Retrieves the currency code (e.g., "USD") for a given currency name.Retrieves the map of currency codes and names.private Double
getCurrencyRate
(Data data, String currency) Retrieves the exchange rate for a specific currency using reflection.javafx.scene.control.ChoiceBox
<String> Retrieves the source currency dropdown.javafx.scene.control.ChoiceBox
<String> Retrieves the target currency dropdown.void
Initializes the controller.
-
Felddetails
-
convertButton
private javafx.scene.control.Button convertButtonThe button that triggers the currency conversion process. When clicked, it validates the input, fetches exchange rates, and displays the converted amount. -
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
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 amountInputFieldThe 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 convertedAmountFieldThe 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
TheCurrencyClient
instance responsible for communicating with the FreeCurrencyAPI. This client is used to fetch real-time exchange rate data. -
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
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
Retrieves the exchange rate for a specific currency using reflection.- Parameter:
data
- TheData
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
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
Retrieves the target currency dropdown.- Gibt zurück:
- The
ChoiceBox
for selecting the target currency.
-
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
Retrieves theCurrencyClient
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
Retrieves the map of currency codes and names.- Gibt zurück:
- A
Map
containing currency codes as keys and names as values.
-