From 022edbc3321c6e8baf76bc5fad30618acd846031 Mon Sep 17 00:00:00 2001 From: La Programmatrice Verde Date: Thu, 5 Mar 2026 21:40:11 +0100 Subject: [PATCH] Pulsante chiudi --- .../RegistrazionePalestra.form | 3 ++ .../RegistrazionePalestra.java | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/registrazionepalestra/RegistrazionePalestra.form b/src/registrazionepalestra/RegistrazionePalestra.form index 20038e7..30ef52a 100644 --- a/src/registrazionepalestra/RegistrazionePalestra.form +++ b/src/registrazionepalestra/RegistrazionePalestra.form @@ -276,6 +276,9 @@ + + + diff --git a/src/registrazionepalestra/RegistrazionePalestra.java b/src/registrazionepalestra/RegistrazionePalestra.java index 590f0f8..71fe407 100644 --- a/src/registrazionepalestra/RegistrazionePalestra.java +++ b/src/registrazionepalestra/RegistrazionePalestra.java @@ -27,6 +27,12 @@ public class RegistrazionePalestra extends javax.swing.JFrame { */ public RegistrazionePalestra() { initComponents(); + addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + btnChiudiActionPerformed(null); + } + }); } /** @@ -38,6 +44,7 @@ public class RegistrazionePalestra extends javax.swing.JFrame { // //GEN-BEGIN:initComponents private void initComponents() { @@ -141,6 +148,7 @@ public class RegistrazionePalestra extends javax.swing.JFrame { btnCancella.addActionListener(this::btnCancellaActionPerformed); btnChiudi.setText("Chiudi"); + btnChiudi.addActionListener(this::btnChiudiActionPerformed); chkFitness.setText("Fitness"); chkFitness.addActionListener(this::chkFitnessActionPerformed); @@ -343,6 +351,35 @@ public class RegistrazionePalestra extends javax.swing.JFrame { pack(); }// //GEN-END:initComponents + private void btnChiudiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnChiudiActionPerformed + + if (isRegistrazioneNonSalvata()) { + switch (JOptionPane.showConfirmDialog(null, "Salvare?", "Esci", JOptionPane.YES_NO_OPTION)) { + case 0: + btnRegistraActionPerformed(evt); + break; + case 1: + System.exit(0); + break; + default: + break; + } + } else { + System.exit(0); + } + }// GEN-LAST:event_btnChiudiActionPerformed + + private boolean isRegistrazioneNonSalvata() { + return !(txtNome.getText().isEmpty() && + txtCognome.getText().isEmpty() && + txtCodiceFiscale.getText().isEmpty() && + txtEmail.getText().isEmpty() && + new String(txtPassword.getPassword()).isEmpty() && + getSelectedSesso() == -1 && + getSelectedCorsi().isEmpty() && + txtaNote.getText().isEmpty()); + } + private void btnCancellaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnCancellaActionPerformed txtNome.setText(""); txtCognome.setText("");