95 lines
2.9 KiB
Java
95 lines
2.9 KiB
Java
package workshop;
|
|
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.control.Alert;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.Button;
|
|
|
|
public class Controller {
|
|
@FXML private Label titleLabel;
|
|
@FXML private Button themeToggle;
|
|
@FXML private Label basicPriceLabel;
|
|
@FXML private Label proPriceLabel;
|
|
@FXML private Label enterprisePriceLabel;
|
|
private boolean isDark = true;
|
|
|
|
//prices
|
|
private int basicPrice = 10;
|
|
private int proPrice = 20;
|
|
private int enterprisePrice = 30;
|
|
|
|
private int clickCount = 0;
|
|
|
|
// TODO: (Optional:For Practice) Create initialize function and use it to set prices during runtime.
|
|
@FXML
|
|
public void initialize() {
|
|
//set prices during runtime
|
|
basicPriceLabel.setText("$" + basicPrice);
|
|
proPriceLabel.setText("$" + proPrice);
|
|
enterprisePriceLabel.setText("$" + enterprisePrice);
|
|
}
|
|
|
|
// TODO: (Optional:For Practice) Make the plan price go 1 dollar up each time user clicks on the shop button.
|
|
@FXML
|
|
private void buyBasic() {
|
|
showAlert("You have entered the payment gateway for Basic Plan ($" + basicPrice + ")");
|
|
increasePrices();
|
|
}
|
|
|
|
private void increasePrices() {
|
|
clickCount++;
|
|
|
|
//After every 3 clicks, prices increase by $1.
|
|
if (clickCount % 3 == 0) {
|
|
basicPrice++;
|
|
proPrice++;
|
|
enterprisePrice++;
|
|
|
|
//updating labels
|
|
basicPriceLabel.setText("$" + basicPrice);
|
|
proPriceLabel.setText("$" + proPrice);
|
|
enterprisePriceLabel.setText("$" + enterprisePrice);
|
|
}
|
|
}
|
|
|
|
@FXML
|
|
private void buyPro() {
|
|
showAlert("You have entered the payment gateway for Pro Plan ($" + proPrice + ")");
|
|
increasePrices();
|
|
}
|
|
|
|
@FXML
|
|
private void buyEnterprise() {
|
|
showAlert("You have entered the payment gateway for Enterprise Plan ($" + enterprisePrice + ")");
|
|
increasePrices();
|
|
}
|
|
|
|
@FXML
|
|
private void toggleTheme() {
|
|
//Get Scene from any Node (themeToggle)
|
|
Scene scene = themeToggle.getScene();
|
|
|
|
if (isDark) {
|
|
//Light Mode
|
|
scene.getStylesheets().clear();
|
|
scene.getStylesheets().add(getClass().getResource("light.css").toExternalForm());
|
|
themeToggle.setText("Switch to Dark Mode");
|
|
isDark = false;
|
|
} else {
|
|
//Dark Mode
|
|
scene.getStylesheets().clear();
|
|
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
|
|
themeToggle.setText("Switch to Light Mode");
|
|
isDark = true;
|
|
}
|
|
}
|
|
|
|
private void showAlert(String message) {
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
alert.setTitle("Payment Gateway");
|
|
alert.setHeaderText("Purchase Confirmation");
|
|
alert.setContentText(message);
|
|
alert.showAndWait();
|
|
}
|
|
} |