Gestione errori
This commit is contained in:
BIN
build/classes/guimybank/GUIMyBank$1.class
Normal file
BIN
build/classes/guimybank/GUIMyBank$1.class
Normal file
Binary file not shown.
BIN
build/classes/guimybank/GUIMyBank$2.class
Normal file
BIN
build/classes/guimybank/GUIMyBank$2.class
Normal file
Binary file not shown.
BIN
build/classes/guimybank/GUIMyBank$3.class
Normal file
BIN
build/classes/guimybank/GUIMyBank$3.class
Normal file
Binary file not shown.
BIN
build/classes/guimybank/GUIMyBank$4.class
Normal file
BIN
build/classes/guimybank/GUIMyBank$4.class
Normal file
Binary file not shown.
BIN
build/classes/guimybank/GUIMyBank$5.class
Normal file
BIN
build/classes/guimybank/GUIMyBank$5.class
Normal file
Binary file not shown.
Binary file not shown.
@@ -139,14 +139,29 @@
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtNome">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtNomeFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtCognome">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtCognomeFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtCodiceFiscale">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtCodiceFiscaleFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtDataDiNascita">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtDataDiNascitaFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtSaldoIniziale">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtSaldoInizialeFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnDataDiNascita">
|
||||
<Properties>
|
||||
|
||||
@@ -139,14 +139,29 @@
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtNome">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtNomeFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtCognome">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtCognomeFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtCodiceFiscale">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtCodiceFiscaleFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtDataDiNascita">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtDataDiNascitaFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtSaldoIniziale">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtSaldoInizialeFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnDataDiNascita">
|
||||
<Properties>
|
||||
|
||||
@@ -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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
|
||||
}// </editor-fold>//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 */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* 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
|
||||
// <editor-fold defaultstate="collapsed" desc=" Look and feel setting code
|
||||
// (optional) ">
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
//</editor-fold>
|
||||
// </editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(() -> new GUIMyBank().setVisible(true));
|
||||
|
||||
Reference in New Issue
Block a user