Initial commit
This commit is contained in:
73
build.xml
Normal file
73
build.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="Verifica_Bassanetti" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Verifica_Bassanetti.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="Verifica_Bassanetti-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
3
manifest.mf
Normal file
3
manifest.mf
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
1420
nbproject/build-impl.xml
Normal file
1420
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@@ -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
|
||||
74
nbproject/project.properties
Normal file
74
nbproject/project.properties
Normal file
@@ -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
|
||||
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>Verifica_Bassanetti</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
32
src/verifica_bassanetti/Contatto.java
Normal file
32
src/verifica_bassanetti/Contatto.java
Normal file
@@ -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 + ")";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
230
src/verifica_bassanetti/Rubrica.form
Normal file
230
src/verifica_bassanetti/Rubrica.form
Normal file
@@ -0,0 +1,230 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnStampa" min="-2" pref="256" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblNumero" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblTipo" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="txtNumero" min="-2" pref="140" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="lblAsterisco3" min="-2" pref="6" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="cmbTipo" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblNome" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblCognome" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="txtCognome" pref="140" max="32767" attributes="0"/>
|
||||
<Component id="txtNome" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblAsterisco1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblAsterisco2" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="btnAggiungiContattoSalva" pref="256" max="32767" attributes="0"/>
|
||||
<Component id="btnVisualizzaRubrica" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" pref="256" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace pref="21" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblNome" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtNome" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblAsterisco1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblCognome" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtCognome" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblAsterisco2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblNumero" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtNumero" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblAsterisco3" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblTipo" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="cmbTipo" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="btnAggiungiContattoSalva" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnVisualizzaRubrica" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="btnStampa" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="btnAggiungiContattoSalva">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Aggiungi Contatto"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAggiungiContattoSalvaActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnVisualizzaRubrica">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Visualizza Rubrica"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnVisualizzaRubricaActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnStampa">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Stampa"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnStampaActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblNome">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Nome:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblCognome">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Cognome:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblNumero">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Numero:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblTipo">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Tipo:"/>
|
||||
</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="txtNumero">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtNumeroFocusGained"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="cmbTipo">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Cellulare"/>
|
||||
<StringItem index="1" value="Casa"/>
|
||||
<StringItem index="2" value="Ufficio"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblAsterisco1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="*"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblAsterisco2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="*"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblAsterisco3">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="*"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextArea" name="txtaVisualizzaRubrica">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
<Property name="rows" type="int" value="5"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
404
src/verifica_bassanetti/Rubrica.java
Normal file
404
src/verifica_bassanetti/Rubrica.java
Normal file
@@ -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<Contatto> 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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
|
||||
}// </editor-fold>//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 */
|
||||
//<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()) {
|
||||
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);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* 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<String> 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
|
||||
}
|
||||
Reference in New Issue
Block a user