Aggiungi conto corrente
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Pattern;
|
||||
import logic.MyBank;
|
||||
import logic.ContoCorrente;
|
||||
@@ -20,7 +22,7 @@ import javax.swing.border.LineBorder;
|
||||
public class GUIMyBank extends javax.swing.JFrame {
|
||||
|
||||
static Border borderOriginale = UIManager.getBorder("TextField.border");
|
||||
static ContoCorrente contoCorrente;
|
||||
static ContoCorrente contoCorrenteAperto;
|
||||
|
||||
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||
.getLogger(GUIMyBank.class.getName());
|
||||
@@ -30,6 +32,9 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
*/
|
||||
public GUIMyBank() {
|
||||
initComponents();
|
||||
lblNumeroContoCorrente.setVisible(false);
|
||||
txtNumeroContoCorrente.setVisible(false);
|
||||
txtNumeroContoCorrente.setEditable(false);
|
||||
btnVersamento.setVisible(false);
|
||||
btnPrelievo.setVisible(false);
|
||||
btnListaMovimenti.setVisible(false);
|
||||
@@ -45,6 +50,7 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
@@ -65,6 +71,8 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
btnListaMovimenti = new javax.swing.JButton();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
txtaListaMovimenti = new javax.swing.JTextArea();
|
||||
lblNumeroContoCorrente = new javax.swing.JLabel();
|
||||
txtNumeroContoCorrente = new javax.swing.JTextField();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
@@ -126,41 +134,14 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
txtaListaMovimenti.setRows(5);
|
||||
jScrollPane1.setViewportView(txtaListaMovimenti);
|
||||
|
||||
lblNumeroContoCorrente.setText("Numero conto corrente:");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(17, 17, 17)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(lblSaldoIniziale))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(btnDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(txtSaldoIniziale))
|
||||
.addGap(37, 37, 37)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(btnVersamento)
|
||||
.addComponent(btnPrelievo)
|
||||
.addComponent(btnListaMovimenti)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(lblCodiceFiscale))
|
||||
.addGap(26, 26, 26)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(99, 99, 99)
|
||||
.addComponent(btnAprireContoCorrente))
|
||||
@@ -168,6 +149,38 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
.addGap(56, 56, 56)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(17, 17, 17)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(lblSaldoIniziale))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(btnDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(txtSaldoIniziale)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(lblCodiceFiscale))
|
||||
.addGap(26, 26, 26)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(lblNumeroContoCorrente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnVersamento)
|
||||
.addComponent(btnPrelievo)
|
||||
.addComponent(btnListaMovimenti)
|
||||
.addComponent(txtNumeroContoCorrente))
|
||||
.addGap(23, 23, 23))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
@@ -175,41 +188,48 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
.addGap(14, 14, 14)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblNumeroContoCorrente))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnVersamento))
|
||||
.addComponent(txtNumeroContoCorrente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCodiceFiscale)
|
||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnPrelievo))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnDataDiNascita)
|
||||
.addComponent(btnListaMovimenti))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblSaldoIniziale)
|
||||
.addComponent(txtSaldoIniziale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCodiceFiscale)
|
||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnDataDiNascita))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblSaldoIniziale)
|
||||
.addComponent(txtSaldoIniziale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnVersamento)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnPrelievo)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnListaMovimenti)))
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnAprireContoCorrente)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(9, Short.MAX_VALUE))
|
||||
.addGap(14, 14, 14))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void btnListaMovimentiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnListaMovimentiActionPerformed
|
||||
private void btnListaMovimentiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnListaMovimentiActionPerformed
|
||||
txtaListaMovimenti.setText(contoCorrente.getLogOperazioni());
|
||||
txtaListaMovimenti.setVisible(true);
|
||||
}//GEN-LAST:event_btnListaMovimentiActionPerformed
|
||||
}// GEN-LAST:event_btnListaMovimentiActionPerformed
|
||||
|
||||
private void txtNomeFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_txtNomeFocusGained
|
||||
txtNome.setBorder(borderOriginale);
|
||||
@@ -273,18 +293,20 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
}// GEN-LAST:event_btnPrelievoActionPerformed
|
||||
|
||||
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 saldoIniziale = txtSaldoIniziale.getText();
|
||||
String nome = txtNome.getText().trim();
|
||||
String cognome = txtCognome.getText().trim();
|
||||
String codiceFiscale = txtCodiceFiscale.getText().trim().toUpperCase();
|
||||
String dataDiNascitaString = txtDataDiNascita.getText().trim();
|
||||
Date dataDiNascita;
|
||||
String saldoInizialeString = txtSaldoIniziale.getText().trim();
|
||||
double saldoIniziale;
|
||||
boolean nomeEmpty = nome.isEmpty();
|
||||
boolean cognomeEmpty = cognome.isEmpty();
|
||||
boolean codiceFiscaleEmpty = codiceFiscale.isEmpty();
|
||||
// boolean dataDiNascitaEmpty = dataDiNascita.isEmpty();
|
||||
boolean saldoInizialeEmpty = saldoIniziale.isEmpty();
|
||||
boolean dataDiNascitaEmpty = dataDiNascitaString.isEmpty();
|
||||
boolean saldoInizialeEmpty = saldoInizialeString.isEmpty();
|
||||
|
||||
if (nomeEmpty || cognomeEmpty || codiceFiscaleEmpty /* || dataDiNascitaEmpty */ || saldoInizialeEmpty) {
|
||||
if (nomeEmpty || cognomeEmpty || codiceFiscaleEmpty || dataDiNascitaEmpty || saldoInizialeEmpty) {
|
||||
if (nomeEmpty) {
|
||||
txtNome.setBorder(new LineBorder(Color.red));
|
||||
}
|
||||
@@ -294,11 +316,9 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
if (codiceFiscaleEmpty) {
|
||||
txtCodiceFiscale.setBorder(new LineBorder(Color.red));
|
||||
}
|
||||
/*
|
||||
* if(dataDiNascitaEmpty){
|
||||
* txtDataDiNascita.setBorder(new LineBorder(Color.red));
|
||||
* }
|
||||
*/
|
||||
if (dataDiNascitaEmpty) {
|
||||
txtDataDiNascita.setBorder(new LineBorder(Color.red));
|
||||
}
|
||||
if (saldoInizialeEmpty) {
|
||||
txtSaldoIniziale.setBorder(new LineBorder(Color.red));
|
||||
}
|
||||
@@ -306,23 +326,33 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCodiceFiscaleValid(codiceFiscale)) {
|
||||
if (MyBank.isCodiceFiscaleValid(codiceFiscale)) {
|
||||
JOptionPane.showMessageDialog(null, "Il codice fiscale non è valido.");
|
||||
txtCodiceFiscale.setBorder(new LineBorder(Color.red));
|
||||
return;
|
||||
}
|
||||
// TODO: gestione data
|
||||
// if(dataDiNascita.isEmpty()){
|
||||
// dataDiNascitaError = true;
|
||||
// }
|
||||
if (!isNumeroValid(saldoIniziale)) {
|
||||
|
||||
try {
|
||||
dataDiNascita = MyBank.dataDiNascita(dataDiNascitaString);
|
||||
} catch (ParseException _) {
|
||||
JOptionPane.showMessageDialog(null, "La data di nascita non è valida.");
|
||||
txtDataDiNascita.setBorder(new LineBorder(Color.red));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
saldoIniziale = MyBank.valoreDouble(saldoInizialeString);
|
||||
} catch (NumberFormatException _) {
|
||||
JOptionPane.showMessageDialog(null, "Il saldo iniziale non è valido.");
|
||||
txtSaldoIniziale.setBorder(new LineBorder(Color.red));
|
||||
return;
|
||||
}
|
||||
|
||||
contoCorrente = new ContoCorrente(nome, cognome, codiceFiscale, Double.parseDouble(saldoIniziale));
|
||||
this.contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale);
|
||||
txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente()));
|
||||
|
||||
lblNumeroContoCorrente.setVisible(true);
|
||||
txtNumeroContoCorrente.setVisible(true);
|
||||
btnVersamento.setVisible(true);
|
||||
btnPrelievo.setVisible(true);
|
||||
btnListaMovimenti.setVisible(true);
|
||||
@@ -336,29 +366,6 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
|
||||
}// 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 isNumeroValid(String numero) {
|
||||
boolean isNumeroValid = true;
|
||||
double valoreNumero;
|
||||
|
||||
try {
|
||||
valoreNumero = Double.parseDouble(numero);
|
||||
|
||||
if (valoreNumero <= 0) {
|
||||
isNumeroValid = false;
|
||||
}
|
||||
} catch (NumberFormatException _) {
|
||||
isNumeroValid = false;
|
||||
}
|
||||
|
||||
return isNumeroValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@@ -399,11 +406,13 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
private javax.swing.JLabel lblCognome;
|
||||
private javax.swing.JLabel lblDataDiNascita;
|
||||
private javax.swing.JLabel lblNome;
|
||||
private javax.swing.JLabel lblNumeroContoCorrente;
|
||||
private javax.swing.JLabel lblSaldoIniziale;
|
||||
private javax.swing.JTextField txtCodiceFiscale;
|
||||
private javax.swing.JTextField txtCognome;
|
||||
private javax.swing.JTextField txtDataDiNascita;
|
||||
private javax.swing.JTextField txtNome;
|
||||
private javax.swing.JTextField txtNumeroContoCorrente;
|
||||
private javax.swing.JTextField txtSaldoIniziale;
|
||||
private javax.swing.JTextArea txtaListaMovimenti;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
Reference in New Issue
Block a user