diff --git a/src/guivendite/GUIVendite.form b/src/guivendite/GUIVendite.form
index b606cd5..056840d 100644
--- a/src/guivendite/GUIVendite.form
+++ b/src/guivendite/GUIVendite.form
@@ -23,13 +23,121 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/guivendite/GUIVendite.java b/src/guivendite/GUIVendite.java
index 0f6b081..2fd8bf3 100644
--- a/src/guivendite/GUIVendite.java
+++ b/src/guivendite/GUIVendite.java
@@ -4,6 +4,10 @@
*/
package guivendite;
+import java.awt.Color;
+import java.util.ArrayList;
+import javax.swing.JOptionPane;
+
/**
*
* @author Verde
@@ -11,7 +15,7 @@ package guivendite;
public class GUIVendite extends javax.swing.JFrame {
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(GUIVendite.class.getName());
-
+ private static ArrayList prodotti = new ArrayList<>();
/**
* Creates new form GUIVendite
*/
@@ -28,22 +32,139 @@ public class GUIVendite extends javax.swing.JFrame {
// //GEN-BEGIN:initComponents
private void initComponents() {
+ lblPrezzo = new javax.swing.JLabel();
+ lblQuantita = new javax.swing.JLabel();
+ lblImportoTotale = new javax.swing.JLabel();
+ txtPrezzo = new javax.swing.JTextField();
+ txtQuantita = new javax.swing.JTextField();
+ txtImportoTotale = new javax.swing.JTextField();
+ btnAggiungi = new javax.swing.JButton();
+ btnPrezzo = new javax.swing.JButton();
+ btnQuantita = new javax.swing.JButton();
+ btnImportoTotale = new javax.swing.JButton();
+
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ lblPrezzo.setText("Prezzo");
+
+ lblQuantita.setText("Quantità ");
+
+ lblImportoTotale.setText("Importo totale");
+
+ txtPrezzo.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtPrezzoFocusGained(evt);
+ }
+ });
+
+
+ txtQuantita.addFocusListener(new java.awt.event.FocusAdapter() {
+ public void focusGained(java.awt.event.FocusEvent evt) {
+ txtQuantitaFocusGained(evt);
+ }
+ });
+
+ txtImportoTotale.setEditable(false);
+
+ btnAggiungi.setText("Aggiungi");
+ btnAggiungi.addActionListener(this::btnAggiungiActionPerformed);
+
+ btnPrezzo.setText("Media prezzo");
+
+ btnQuantita.setText("Media quantità ");
+
+ btnImportoTotale.setText("Tot. vendite");
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(19, 19, 19)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(lblPrezzo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(lblQuantita, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(btnPrezzo)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(btnQuantita))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(txtPrezzo, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(txtQuantita)))
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(btnImportoTotale)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(txtImportoTotale, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
+ .addGap(27, 27, 27)
+ .addComponent(btnAggiungi)
+ .addGap(22, 22, 22))
+ .addComponent(lblImportoTotale, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(lblPrezzo)
+ .addComponent(lblQuantita)
+ .addComponent(lblImportoTotale))
+ .addGap(26, 26, 26)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(txtPrezzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(txtQuantita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(txtImportoTotale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(btnAggiungi))
+ .addGap(26, 26, 26)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(btnPrezzo)
+ .addComponent(btnQuantita)
+ .addComponent(btnImportoTotale))
+ .addContainerGap(23, Short.MAX_VALUE))
);
pack();
}// //GEN-END:initComponents
+ private void btnAggiungiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAggiungiActionPerformed
+ double quantita = leggiCampo(txtQuantita);
+ double prezzo = leggiCampo(txtPrezzo);
+
+ if(quantita > 0 && prezzo > 0){
+ prodotti.add(new Prodotto(quantita, prezzo));
+ txtImportoTotale.setText(Double.toString(prodotti.getLast().getTotale()));
+ }
+ }//GEN-LAST:event_btnAggiungiActionPerformed
+
+ private void txtPrezzoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrezzoFocusGained
+ txtPrezzo.setBackground(Color.white);
+ }//GEN-LAST:event_txtPrezzoFocusGained
+
+ private void txtQuantitaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQuantitaFocusGained
+ txtQuantita.setBackground(Color.white);
+ }//GEN-LAST:event_txtQuantitaFocusGained
+
+ private double leggiCampo(javax.swing.JTextField campo){
+ double valoreCampo = -1;
+
+ try{
+ valoreCampo = Double.parseDouble(campo.getText());
+ if(valoreCampo <= 0){
+ JOptionPane.showMessageDialog(null, "Inserire un numero maggiore di zero.");
+ campo.setBackground(Color.red);
+ }
+ } catch(NumberFormatException _){
+ JOptionPane.showMessageDialog(null, "Inserire un numero valido.");
+ campo.setBackground(Color.red);
+ }
+
+ return valoreCampo;
+ }
+
/**
* @param args the command line arguments
*/
@@ -70,5 +191,15 @@ public class GUIVendite extends javax.swing.JFrame {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton btnAggiungi;
+ private javax.swing.JButton btnImportoTotale;
+ private javax.swing.JButton btnPrezzo;
+ private javax.swing.JButton btnQuantita;
+ private javax.swing.JLabel lblImportoTotale;
+ private javax.swing.JLabel lblPrezzo;
+ private javax.swing.JLabel lblQuantita;
+ private javax.swing.JTextField txtImportoTotale;
+ private javax.swing.JTextField txtPrezzo;
+ private javax.swing.JTextField txtQuantita;
// End of variables declaration//GEN-END:variables
}