Package Application
Package Application
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@Override
root.setPrefSize(528, 385);
Text title = new Text("GESTION DE COMPTE");
title.setLayoutX(173);
title.setLayoutY(60);
root.getChildren().add(title);
codeLabel.setFill(javafx.scene.paint.Color.valueOf("#131414"));
codeLabel.setLayoutX(88);
codeLabel.setLayoutY(107);
root.getChildren().add(codeLabel);
montantLabel.setLayoutX(88);
montantLabel.setLayoutY(163);
root.getChildren().add(montantLabel);
codeField.setPromptText("entrer le matricule");
codeField.setLayoutX(171);
codeField.setLayoutY(86);
codeField.setPrefSize(231, 26);
root.getChildren().add(codeField);
montantField.setPromptText("entrer le montant");
montantField.setLayoutX(171);
montantField.setLayoutY(144);
montantField.setPrefSize(231, 26);
root.getChildren().add(montantField);
+ "-fx-text-fill: white;");
retirerButton.setFont(Font.font(15));
retirerButton.setLayoutX(121);
retirerButton.setLayoutY(228);
root.getChildren().add(retirerButton);
+ "-fx-text-fill: white;");
virerButton.setFont(Font.font(15));
virerButton.setLayoutX(207);
virerButton.setLayoutY(228);
root.getChildren().add(virerButton);
+ "-fx-text-fill: white;");
verserButton.setFont(Font.font(15));
verserButton.setLayoutX(287);
verserButton.setLayoutY(228);
root.getChildren().add(verserButton);
soldeButton.setStyle("-fx-background-color: blue;"
+ "-fx-text-fill: white;");
soldeButton.setFont(Font.font(15));
soldeButton.setLayoutX(368);
soldeButton.setLayoutY(228);
root.getChildren().add(soldeButton);
verserButton.setOnAction(event -> {
if (code.isEmpty() || montant.isEmpty()) {
} else {
verserMontant(code, montant);
});
retirerButton.setOnAction(event -> {
if (code.isEmpty() || montant.isEmpty()) {
} else {
retirerMontant(code, montant);
});
soldeButton.setOnAction(event -> {
if (code.isEmpty()) {
showAlert(Alert.AlertType.WARNING, "Veuillez entrer le matricule.");
} else {
afficherSolde(code);
});
primaryStage.setTitle("Gestion de Compte");
primaryStage.setScene(scene);
primaryStage.show();
};
virementRoot.setPrefSize(528, 385);
title.setLayoutX(191);
title.setLayoutY(60);
virementRoot.getChildren().add(title);
codeLabel.setLayoutX(70);
codeLabel.setLayoutY(105);
virementRoot.getChildren().add(codeLabel);
montantLabel.setLayoutX(70);
montantLabel.setLayoutY(163);
virementRoot.getChildren().add(montantLabel);
Text beneficiaireLabel = new Text("Beneficiaire:");
beneficiaireLabel.setLayoutX(70);
beneficiaireLabel.setLayoutY(230);
virementRoot.getChildren().add(beneficiaireLabel);
codeField.setPromptText("entrer le matricule");
codeField.setLayoutX(171);
codeField.setLayoutY(86);
codeField.setPrefSize(231, 26);
virementRoot.getChildren().add(codeField);
montantField.setPromptText("entrer le montant");
montantField.setLayoutX(173);
montantField.setLayoutY(144);
montantField.setPrefSize(231, 26);
virementRoot.getChildren().add(montantField);
beneficiaireField.setLayoutX(173);
beneficiaireField.setLayoutY(209);
beneficiaireField.setPrefSize(231, 26);
virementRoot.getChildren().add(beneficiaireField);
retourButton.setFont(Font.font(15));
retourButton.setLayoutX(61);
retourButton.setLayoutY(290);
effectuerButton.setFont(Font.font(15));
effectuerButton.setLayoutX(354);
effectuerButton.setLayoutY(290);
effectuerButton.setOnAction(event -> {
return;
try {
if (montant <= 0) {
return;
} catch (NumberFormatException e) {
});
virementRoot.getChildren().add(effectuerButton);
virementStage.setTitle("Virement");
virementStage.setScene(virementScene);
virementStage.show();
checkSoldeStmt.setString(1, codeEmetteur);
ResultSet rs = checkSoldeStmt.executeQuery();
if (!rs.next()) {
return;
return;
PreparedStatement checkBeneficiaireStmt =
connection.prepareStatement(checkBeneficiaireQuery);
checkBeneficiaireStmt.setString(1, codeBeneficiaire);
if (!rsBeneficiaire.next()) {
showAlert(Alert.AlertType.ERROR, "Compte bénéficiaire introuvable.");
return;
String debitQuery = "UPDATE compte SET solde = solde - ? WHERE code = ?";
debitStmt.setDouble(1, montant);
debitStmt.setString(2, codeEmetteur);
debitStmt.executeUpdate();
String creditQuery = "UPDATE compte SET solde = solde + ? WHERE code = ?";
creditStmt.setDouble(1, montant);
creditStmt.setString(2, codeBeneficiaire);
creditStmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
String query = "UPDATE compte SET solde = solde + ? WHERE code = ?";
preparedStatement.setDouble(1, Double.parseDouble(montant));
preparedStatement.setString(2, code);
} else {
} catch (SQLException e) {
e.printStackTrace();
checkStatement.setString(1, code);
if (resultSet.next()) {
} else {
String query = "UPDATE compte SET solde = solde - ? WHERE code = ?";
preparedStatement.setDouble(1, montantDouble);
preparedStatement.setString(2, code);
int rowsUpdated = preparedStatement.executeUpdate();
if (rowsUpdated > 0) {
} else {
} else {
} catch (SQLException e) {
e.printStackTrace();
preparedStatement.setString(1, code);
if (resultSet.next()) {
} else {
}
} catch (SQLException e) {
e.printStackTrace();
alert.setContentText(message);
alert.showAndWait();
launch(args);