diff --git a/build/classes/guimybank/GUIMyBank$1.class b/build/classes/guimybank/GUIMyBank$1.class
new file mode 100644
index 0000000..b4bca6d
Binary files /dev/null and b/build/classes/guimybank/GUIMyBank$1.class differ
diff --git a/build/classes/guimybank/GUIMyBank$2.class b/build/classes/guimybank/GUIMyBank$2.class
new file mode 100644
index 0000000..b0f0995
Binary files /dev/null and b/build/classes/guimybank/GUIMyBank$2.class differ
diff --git a/build/classes/guimybank/GUIMyBank$3.class b/build/classes/guimybank/GUIMyBank$3.class
new file mode 100644
index 0000000..5c1c76f
Binary files /dev/null and b/build/classes/guimybank/GUIMyBank$3.class differ
diff --git a/build/classes/guimybank/GUIMyBank$4.class b/build/classes/guimybank/GUIMyBank$4.class
new file mode 100644
index 0000000..f9e12aa
Binary files /dev/null and b/build/classes/guimybank/GUIMyBank$4.class differ
diff --git a/build/classes/guimybank/GUIMyBank$5.class b/build/classes/guimybank/GUIMyBank$5.class
new file mode 100644
index 0000000..b686be0
Binary files /dev/null and b/build/classes/guimybank/GUIMyBank$5.class differ
diff --git a/build/classes/guimybank/GUIMyBank.class b/build/classes/guimybank/GUIMyBank.class
index 8da090e..5e8a4d7 100644
Binary files a/build/classes/guimybank/GUIMyBank.class and b/build/classes/guimybank/GUIMyBank.class differ
diff --git a/build/classes/guimybank/GUIMyBank.form b/build/classes/guimybank/GUIMyBank.form
index 30b639f..e4ca2ee 100644
--- a/build/classes/guimybank/GUIMyBank.form
+++ b/build/classes/guimybank/GUIMyBank.form
@@ -139,14 +139,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/guimybank/GUIMyBank.form b/src/guimybank/GUIMyBank.form
index 30b639f..e4ca2ee 100644
--- a/src/guimybank/GUIMyBank.form
+++ b/src/guimybank/GUIMyBank.form
@@ -139,14 +139,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/guimybank/GUIMyBank.java b/src/guimybank/GUIMyBank.java
index d65fc40..ed46b3a 100644
--- a/src/guimybank/GUIMyBank.java
+++ b/src/guimybank/GUIMyBank.java
@@ -5,7 +5,11 @@
package guimybank;
import java.awt.Color;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import javax.swing.JOptionPane;
+import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
@@ -15,7 +19,10 @@ import javax.swing.border.LineBorder;
*/
public class GUIMyBank extends javax.swing.JFrame {
- private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(GUIMyBank.class.getName());
+ static Border borderOriginale = UIManager.getBorder("TextField.border");
+
+ private static final java.util.logging.Logger logger = java.util.logging.Logger
+ .getLogger(GUIMyBank.class.getName());
/**
* Creates new form GUIMyBank
@@ -33,6 +40,7 @@ public class GUIMyBank extends javax.swing.JFrame {
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
private void initComponents() {
@@ -64,6 +72,36 @@ public class GUIMyBank extends javax.swing.JFrame {
lblSaldoIniziale.setText("Saldo iniziale");
+ txtNome.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtNomeFocusGained(evt);
+ }
+ });
+
+ txtCognome.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtCognomeFocusGained(evt);
+ }
+ });
+
+ txtCodiceFiscale.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtCodiceFiscaleFocusGained(evt);
+ }
+ });
+
+ txtDataDiNascita.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtDataDiNascitaFocusGained(evt);
+ }
+ });
+
+ txtSaldoIniziale.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtSaldoInizialeFocusGained(evt);
+ }
+ });
+
btnDataDiNascita.setText("[]");
btnAprireContoCorrente.setText("Aprire conto corrente");
@@ -150,40 +188,75 @@ public class GUIMyBank extends javax.swing.JFrame {
pack();
}// //GEN-END:initComponents
- private void btnAprireContoCorrenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAprireContoCorrenteActionPerformed
+ private void txtNomeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNomeFocusGained
+txtNome.setBorder(borderOriginale);
+ }//GEN-LAST:event_txtNomeFocusGained
+
+ private void txtCognomeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCognomeFocusGained
+txtCognome.setBorder(borderOriginale);
+ }//GEN-LAST:event_txtCognomeFocusGained
+
+ private void txtCodiceFiscaleFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCodiceFiscaleFocusGained
+ txtCodiceFiscale.setBorder(borderOriginale);
+ }//GEN-LAST:event_txtCodiceFiscaleFocusGained
+
+ private void txtDataDiNascitaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDataDiNascitaFocusGained
+ txtDataDiNascita.setBorder(borderOriginale);
+ }//GEN-LAST:event_txtDataDiNascitaFocusGained
+
+ private void txtSaldoInizialeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSaldoInizialeFocusGained
+ txtSaldoIniziale.setBorder(borderOriginale);
+ }//GEN-LAST:event_txtSaldoInizialeFocusGained
+
+ private void btnAprireContoCorrenteActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnAprireContoCorrenteActionPerformed
String nome = txtNome.getText();
String cognome = txtCognome.getText();
String codiceFiscale = txtCodiceFiscale.getText();
- String dataDiNascita = txtDataDiNascita.getText();
+ // String dataDiNascita = txtDataDiNascita.getText();
String saldoIniziale = txtSaldoIniziale.getText();
-
- if(nome.isEmpty()){
- JOptionPane.showMessageDialog(null, "Inserire il proprio nome.");
- txtNome.setBorder(new LineBorder(Color.red));
+ boolean nomeEmpty = nome.isEmpty();
+ boolean cognomeEmpty = cognome.isEmpty();
+ boolean codiceFiscaleEmpty = codiceFiscale.isEmpty();
+ // boolean dataDiNascitaEmpty = dataDiNascita.isEmpty();
+ boolean saldoInizialeEmpty = saldoIniziale.isEmpty();
+
+ if (nomeEmpty || cognomeEmpty || codiceFiscaleEmpty /* || dataDiNascitaEmpty */ || saldoInizialeEmpty) {
+ if (nomeEmpty) {
+ txtNome.setBorder(new LineBorder(Color.red));
+ }
+ if (cognomeEmpty) {
+ txtCognome.setBorder(new LineBorder(Color.red));
+ }
+ if (codiceFiscaleEmpty) {
+ txtCodiceFiscale.setBorder(new LineBorder(Color.red));
+ }
+ /*
+ * if(dataDiNascitaEmpty){
+ * txtDataDiNascita.setBorder(new LineBorder(Color.red));
+ * }
+ */
+ if (saldoInizialeEmpty) {
+ txtSaldoIniziale.setBorder(new LineBorder(Color.red));
+ }
+ JOptionPane.showMessageDialog(null, "Inserire tutti i dati richiesti.");
return;
}
- if(cognome.isEmpty()){
- JOptionPane.showMessageDialog(null, "Inserire il proprio cognome.");
- txtCognome.setBorder(new LineBorder(Color.red));
- return;
- }
- //TODO: verifica codice fiscale
- if(codiceFiscale.isEmpty()){
- JOptionPane.showMessageDialog(null, "Inserire il proprio codice fiscale.");
+
+ if (isCodiceFiscaleValid(codiceFiscale)) {
+ JOptionPane.showMessageDialog(null, "Il codice fiscale non è valido.");
txtCodiceFiscale.setBorder(new LineBorder(Color.red));
return;
}
- //TODO: gestione data
- //if(dataDiNascita.isEmpty()){
- // JOptionPane.showMessageDialog(null, "Inserire la propria data di nascita.");
- // txtDataDiNascita.setBorder(new LineBorder(Color.red));
- // return;
- //}
- if(saldoIniziale.isEmpty()){
- JOptionPane.showMessageDialog(null, "Inserire il proprio saldo iniziale.");
+ // TODO: gestione data
+ // if(dataDiNascita.isEmpty()){
+ // dataDiNascitaError = true;
+ // }
+ if (!isSaldoInizialeValid(saldoIniziale)) {
+ JOptionPane.showMessageDialog(null, "Il saldo iniziale non è valido.");
txtSaldoIniziale.setBorder(new LineBorder(Color.red));
return;
}
+
btnVersamento.setVisible(true);
btnPrelievo.setVisible(true);
btnListaMovimenti.setVisible(true);
@@ -192,17 +265,44 @@ public class GUIMyBank extends javax.swing.JFrame {
txtCodiceFiscale.setEditable(false);
txtDataDiNascita.setEditable(false);
txtSaldoIniziale.setEditable(false);
-
- }//GEN-LAST:event_btnAprireContoCorrenteActionPerformed
+
+ }// GEN-LAST:event_btnAprireContoCorrenteActionPerformed
+
+ boolean isCodiceFiscaleValid(String codiceFiscale) {
+ Pattern pattern = Pattern.compile("[A-Z]{6}[ABCDEHLMPRST]{3}\\d{2}[A-Z]\\d{3}[A-Z]");
+
+ return !pattern.matcher(codiceFiscale).find();
+ }
+
+ boolean isSaldoInizialeValid(String saldoIniziale) {
+ boolean isSaldoInizialeValid = true;
+ double valoreSaldoIniziale;
+
+ try {
+ valoreSaldoIniziale = Double.parseDouble(saldoIniziale);
+
+ if (valoreSaldoIniziale <= 0) {
+ isSaldoInizialeValid = false;
+ }
+ } catch (NumberFormatException _) {
+ isSaldoInizialeValid = false;
+ }
+
+ return isSaldoInizialeValid;
+ }
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
- //
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ //
+ /*
+ * If Nimbus (introduced in Java SE 6) is not available, stay with the default
+ * look and feel.
+ * For details see
+ * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
@@ -214,7 +314,7 @@ public class GUIMyBank extends javax.swing.JFrame {
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
logger.log(java.util.logging.Level.SEVERE, null, ex);
}
- //
+ //
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> new GUIMyBank().setVisible(true));