From 8bbc4937b0ded526a246fd89f1b851d7e891df2d Mon Sep 17 00:00:00 2001 From: La Programmatrice Verde Date: Thu, 16 Apr 2026 10:55:39 +0200 Subject: [PATCH] Initial commit --- build.xml | 73 ++ manifest.mf | 3 + nbproject/build-impl.xml | 1420 +++++++++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 74 ++ nbproject/project.xml | 15 + src/verifica_bassanetti/Contatto.java | 32 + src/verifica_bassanetti/Rubrica.form | 230 ++++ src/verifica_bassanetti/Rubrica.java | 404 +++++++ 9 files changed, 2259 insertions(+) create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/verifica_bassanetti/Contatto.java create mode 100644 src/verifica_bassanetti/Rubrica.form create mode 100644 src/verifica_bassanetti/Rubrica.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..efe9c29 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Verifica_Bassanetti. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..2c0f885 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..150e10d --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=27e4cadd +build.xml.script.CRC32=55c5382a +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=27e4cadd +nbproject/build-impl.xml.script.CRC32=ac86efef +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..0d1695b --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Verifica_Bassanetti.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=verifica_bassanetti.Rubrica +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..1839558 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Verifica_Bassanetti + + + + + + + + + diff --git a/src/verifica_bassanetti/Contatto.java b/src/verifica_bassanetti/Contatto.java new file mode 100644 index 0000000..b6b82eb --- /dev/null +++ b/src/verifica_bassanetti/Contatto.java @@ -0,0 +1,32 @@ +package verifica_bassanetti; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author alunno + */ +public class Contatto { + private final String nome; + private final String cognome; + private final String numero; + private final String tipoNumero; + + public Contatto(String nome, String cognome, String numero, String tipoNumero) { + this.nome = nome; + this.cognome = cognome; + this.numero = numero; + this.tipoNumero = tipoNumero; + } + + @Override + public String toString(){ + return this.nome + " " + this.cognome + " " + this.numero + " (" + this.tipoNumero + ")"; + } + + +} diff --git a/src/verifica_bassanetti/Rubrica.form b/src/verifica_bassanetti/Rubrica.form new file mode 100644 index 0000000..90d8844 --- /dev/null +++ b/src/verifica_bassanetti/Rubrica.form @@ -0,0 +1,230 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/verifica_bassanetti/Rubrica.java b/src/verifica_bassanetti/Rubrica.java new file mode 100644 index 0000000..3ba019b --- /dev/null +++ b/src/verifica_bassanetti/Rubrica.java @@ -0,0 +1,404 @@ +package verifica_bassanetti; + +import java.awt.Color; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.LinkedList; +import java.util.regex.Pattern; +import javax.swing.JOptionPane; +import javax.swing.border.LineBorder; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author alunno + */ +public class Rubrica extends javax.swing.JFrame { + + private final LinkedList rubrica = new LinkedList<>(); + private static final String PATH_RUBRICA = "./src/verifica_bassanetti/rubrica.txt"; + + /** + * Creates new form Rubrica + */ + public Rubrica() { + initComponents(); + lblNome.setVisible(false); + lblCognome.setVisible(false); + lblNumero.setVisible(false); + lblTipo.setVisible(false); + lblAsterisco1.setVisible(false); + lblAsterisco2.setVisible(false); + lblAsterisco3.setVisible(false); + txtNome.setVisible(false); + txtNome.setEditable(false); + txtNome.setBorder(null); + txtCognome.setVisible(false); + txtCognome.setEditable(false); + txtCognome.setBorder(null); + txtNumero.setVisible(false); + txtNumero.setEditable(false); + txtNumero.setBorder(null); + cmbTipo.setVisible(false); + cmbTipo.setEditable(false); + txtaVisualizzaRubrica.setVisible(false); + txtaVisualizzaRubrica.setEnabled(false); + txtaVisualizzaRubrica.setEditable(false); + txtaVisualizzaRubrica.setBorder(null); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + btnAggiungiContattoSalva = new javax.swing.JButton(); + btnVisualizzaRubrica = new javax.swing.JButton(); + btnStampa = new javax.swing.JButton(); + lblNome = new javax.swing.JLabel(); + lblCognome = new javax.swing.JLabel(); + lblNumero = new javax.swing.JLabel(); + lblTipo = new javax.swing.JLabel(); + txtNome = new javax.swing.JTextField(); + txtCognome = new javax.swing.JTextField(); + txtNumero = new javax.swing.JTextField(); + cmbTipo = new javax.swing.JComboBox<>(); + lblAsterisco1 = new javax.swing.JLabel(); + lblAsterisco2 = new javax.swing.JLabel(); + lblAsterisco3 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + txtaVisualizzaRubrica = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + btnAggiungiContattoSalva.setText("Aggiungi Contatto"); + btnAggiungiContattoSalva.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnAggiungiContattoSalvaActionPerformed(evt); + } + }); + + btnVisualizzaRubrica.setText("Visualizza Rubrica"); + btnVisualizzaRubrica.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnVisualizzaRubricaActionPerformed(evt); + } + }); + + btnStampa.setText("Stampa"); + btnStampa.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnStampaActionPerformed(evt); + } + }); + + lblNome.setText("Nome:"); + + lblCognome.setText("Cognome:"); + + lblNumero.setText("Numero:"); + + lblTipo.setText("Tipo:"); + + 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); + } + }); + + txtNumero.addFocusListener(new java.awt.event.FocusAdapter() { + public void focusGained(java.awt.event.FocusEvent evt) { + txtNumeroFocusGained(evt); + } + }); + + cmbTipo.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Cellulare", "Casa", "Ufficio" })); + + lblAsterisco1.setText("*"); + + lblAsterisco2.setText("*"); + + lblAsterisco3.setText("*"); + + txtaVisualizzaRubrica.setColumns(20); + txtaVisualizzaRubrica.setRows(5); + jScrollPane1.setViewportView(txtaVisualizzaRubrica); + + 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.TRAILING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(btnStampa, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addGap(26, 26, 26) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblNumero) + .addComponent(lblTipo)) + .addGap(22, 22, 22) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(lblAsterisco3, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblNome) + .addComponent(lblCognome)) + .addGap(14, 14, 14) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(txtCognome, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE) + .addComponent(txtNome)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblAsterisco1) + .addComponent(lblAsterisco2))))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(btnAggiungiContattoSalva, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) + .addComponent(btnVisualizzaRubrica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)))) + .addContainerGap(21, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(25, 25, 25) + .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(lblAsterisco1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .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(lblAsterisco2)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblNumero) + .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblAsterisco3)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lblTipo) + .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btnAggiungiContattoSalva) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnVisualizzaRubrica) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(btnStampa) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void btnAggiungiContattoSalvaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAggiungiContattoSalvaActionPerformed + if (btnAggiungiContattoSalva.getText().equals("Aggiungi Contatto")) { + lblNome.setVisible(true); + lblCognome.setVisible(true); + lblNumero.setVisible(true); + lblTipo.setVisible(true); + lblAsterisco1.setVisible(true); + lblAsterisco2.setVisible(true); + lblAsterisco3.setVisible(true); + txtNome.setVisible(true); + txtNome.setEditable(true); + txtCognome.setVisible(true); + txtCognome.setEditable(true); + txtNumero.setVisible(true); + txtNumero.setEditable(true); + cmbTipo.setVisible(true); + cmbTipo.setEditable(true); + btnAggiungiContattoSalva.setText("Salva"); + btnVisualizzaRubrica.setVisible(false); + btnVisualizzaRubrica.setEnabled(false); + btnStampa.setVisible(false); + btnStampa.setEnabled(false); + txtaVisualizzaRubrica.setVisible(false); + txtaVisualizzaRubrica.setEnabled(false); + + } else { + if (controlloInput()) { + rubrica.add(new Contatto(txtNome.getText(), txtCognome.getText(), txtNumero.getText(), (String) cmbTipo.getSelectedItem())); + JOptionPane.showMessageDialog(null, "Contatto agguiunto con successo"); + lblNome.setVisible(false); + lblCognome.setVisible(false); + lblNumero.setVisible(false); + lblTipo.setVisible(false); + lblAsterisco1.setVisible(false); + lblAsterisco2.setVisible(false); + lblAsterisco3.setVisible(false); + txtNome.setVisible(false); + txtNome.setEditable(false); + txtNome.setText(""); + txtCognome.setVisible(false); + txtCognome.setEditable(false); + txtCognome.setText(""); + txtNumero.setVisible(false); + txtNumero.setEditable(false); + txtNumero.setText(""); + cmbTipo.setVisible(false); + cmbTipo.setEditable(false); + cmbTipo.setSelectedIndex(0); + btnAggiungiContattoSalva.setText("Aggiungi Contatto"); + btnVisualizzaRubrica.setVisible(true); + btnVisualizzaRubrica.setEnabled(true); + btnStampa.setVisible(true); + btnStampa.setEnabled(true); + } + + } + }//GEN-LAST:event_btnAggiungiContattoSalvaActionPerformed + + private void txtNomeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNomeFocusGained + txtNome.setBorder(null); + }//GEN-LAST:event_txtNomeFocusGained + + private void txtCognomeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCognomeFocusGained + txtCognome.setBorder(null); + }//GEN-LAST:event_txtCognomeFocusGained + + private void txtNumeroFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNumeroFocusGained + txtNumero.setBorder(null); + }//GEN-LAST:event_txtNumeroFocusGained + + private void btnVisualizzaRubricaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVisualizzaRubricaActionPerformed + if (rubrica.isEmpty()) { + JOptionPane.showMessageDialog(null, "Nessun contatto inserito", "Errore", JOptionPane.ERROR_MESSAGE); + } else { + txtaVisualizzaRubrica.setText(rubricaToString()); + txtaVisualizzaRubrica.setVisible(true); + txtaVisualizzaRubrica.setEnabled(true); + } + }//GEN-LAST:event_btnVisualizzaRubricaActionPerformed + + private String rubricaToString() { + StringBuilder sb = new StringBuilder(); + int indice = 1; + for (Contatto contatto : rubrica) { + sb.append(indice++); + sb.append(" - "); + sb.append(contatto.toString()); + sb.append("\n"); + } + return sb.toString(); + } + private void btnStampaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStampaActionPerformed + try (BufferedWriter bw = new BufferedWriter(new FileWriter(PATH_RUBRICA))) { + if (rubricaToString().isEmpty()) { + JOptionPane.showMessageDialog(null, "Nesusn contatto è stato salvato, la rubrica è vuota.", "Attenzione", JOptionPane.WARNING_MESSAGE); + } else { + bw.write(rubricaToString()); + JOptionPane.showMessageDialog(null, "Rubrica salvata con successo."); + } + } catch (IOException e) { + JOptionPane.showMessageDialog(null, "Errore nel salvataggio dei contatti:\n" + e.getMessage(), "Errore", JOptionPane.ERROR_MESSAGE); + } finally{ + txtaVisualizzaRubrica.setVisible(false); + txtaVisualizzaRubrica.setEnabled(false); + } + }//GEN-LAST:event_btnStampaActionPerformed + + private boolean controlloInput() { + boolean error = false; + if (txtNome.getText().isEmpty()) { + txtNome.setBorder(new LineBorder(Color.red)); + error = true; + } + if (txtCognome.getText().isEmpty()) { + txtCognome.setBorder(new LineBorder(Color.red)); + error = true; + } + if (txtNumero.getText().isEmpty()) { + txtNumero.setBorder(new LineBorder(Color.red)); + error = true; + } + + if (error) { + JOptionPane.showMessageDialog(null, "Inserire tutti i campi richiesti.\nSono indicati dall'asterisco.", "Errore", JOptionPane.ERROR_MESSAGE); + } + + return !error; + } + + /** + * @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 + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(Rubrica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Rubrica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Rubrica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Rubrica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(() -> { + new Rubrica().setVisible(true); + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnAggiungiContattoSalva; + private javax.swing.JButton btnStampa; + private javax.swing.JButton btnVisualizzaRubrica; + private javax.swing.JComboBox cmbTipo; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JLabel lblAsterisco1; + private javax.swing.JLabel lblAsterisco2; + private javax.swing.JLabel lblAsterisco3; + private javax.swing.JLabel lblCognome; + private javax.swing.JLabel lblNome; + private javax.swing.JLabel lblNumero; + private javax.swing.JLabel lblTipo; + private javax.swing.JTextField txtCognome; + private javax.swing.JTextField txtNome; + private javax.swing.JTextField txtNumero; + private javax.swing.JTextArea txtaVisualizzaRubrica; + // End of variables declaration//GEN-END:variables +}