Implementation with class
This commit is contained in:
@@ -1,39 +1,72 @@
|
||||
package workshop;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
public class Controller {
|
||||
@FXML private Label basePrise;
|
||||
private int price = 12;
|
||||
@FXML private Label titleLabel;
|
||||
@FXML private Button themeToggle;
|
||||
|
||||
private boolean isDark = true;
|
||||
|
||||
// TODO: (Optional) Create initialize function and use it to set prices during runtime.
|
||||
@FXML
|
||||
public void initialize()
|
||||
{
|
||||
basePrise.setText("$" + price + " / month");
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
private void buyBasic() {
|
||||
// TODO: Call showAlert() with a message indicating the user entered the payment gateway
|
||||
price++;
|
||||
basePrise.setText("$" + price + " / month");
|
||||
showAlert("Basic plan selected.", Alert.AlertType.INFORMATION);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void buyPro() {
|
||||
// TODO: Call showAlert() with a message indicating the user entered the payment gateway
|
||||
showAlert("Pro plan selected.", Alert.AlertType.INFORMATION);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void buyEnterprise() {
|
||||
// TODO: Call showAlert() with a message indicating the user entered the payment gateway
|
||||
showAlert("Enterprise plan selected.", Alert.AlertType.INFORMATION);
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void toggleTheme() {
|
||||
isDark = !isDark;
|
||||
themeToggle.getScene().getStylesheets().clear();
|
||||
if(isDark)
|
||||
{
|
||||
themeToggle.getScene().getStylesheets().add(getClass().getResource("style.css").toExternalForm());
|
||||
themeToggle.setText("Switch to Light Mode");
|
||||
}
|
||||
else
|
||||
{
|
||||
themeToggle.getScene().getStylesheets().add(getClass().getResource("light.css").toExternalForm());
|
||||
themeToggle.setText("Switch to Dark Mode");
|
||||
}
|
||||
// TODO: Toggle the isDark flag. If dark, switch to style.css and set button text to "Switch to Light Mode"
|
||||
// TODO: If light, switch to light.css and set button text to "Switch to Dark Mode"
|
||||
}
|
||||
|
||||
private void showAlert(String message) {
|
||||
private void showAlert(String message, Alert.AlertType alertType) {
|
||||
// TODO: Create a new Alert of type INFORMATION with the given message and display it
|
||||
Alert alert = new Alert(alertType);
|
||||
alert.setTitle("Alert");
|
||||
alert.setHeaderText("Header");
|
||||
alert.setContentText(message);
|
||||
alert.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user