Operazioni prodotti multipli

This commit is contained in:
La Programmatrice Verde
2026-01-25 13:57:47 +01:00
parent bee12abffb
commit 778c3ed062
2 changed files with 39 additions and 11 deletions

View File

@@ -101,14 +101,10 @@
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPrezzo">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPrezzoActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtQuantita">
<Events>
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtQuantitaFocusGained"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtQuantitaActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtImportoTotale">
@@ -128,16 +124,25 @@
<Properties>
<Property name="text" type="java.lang.String" value="Media prezzo"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPrezzoActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnQuantita">
<Properties>
<Property name="text" type="java.lang.String" value="Media quantit&#xe0;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuantitaActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnImportoTotale">
<Properties>
<Property name="text" type="java.lang.String" value="Tot. vendite"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnImportoTotaleActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -51,13 +51,6 @@ public class GUIVendite extends javax.swing.JFrame {
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);
@@ -70,10 +63,13 @@ public class GUIVendite extends javax.swing.JFrame {
btnAggiungi.addActionListener(this::btnAggiungiActionPerformed);
btnPrezzo.setText("Media prezzo");
btnPrezzo.addActionListener(this::btnPrezzoActionPerformed);
btnQuantita.setText("Media quantità");
btnQuantita.addActionListener(this::btnQuantitaActionPerformed);
btnImportoTotale.setText("Tot. vendite");
btnImportoTotale.addActionListener(this::btnImportoTotaleActionPerformed);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@@ -148,6 +144,33 @@ public class GUIVendite extends javax.swing.JFrame {
txtQuantita.setBackground(Color.white);
}//GEN-LAST:event_txtQuantitaFocusGained
private void btnPrezzoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrezzoActionPerformed
double totale = 0;
for(Prodotto prodotto: prodotti){
totale += prodotto.getPrezzo();
}
txtPrezzo.setText(Double.toString(totale/prodotti.size()));
}//GEN-LAST:event_btnPrezzoActionPerformed
private void btnQuantitaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuantitaActionPerformed
double totale = 0;
for(Prodotto prodotto: prodotti){
totale += prodotto.getQuantita();
}
txtQuantita.setText(Double.toString(totale/prodotti.size()));
}//GEN-LAST:event_btnQuantitaActionPerformed
private void btnImportoTotaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportoTotaleActionPerformed
double totale = 0;
for(Prodotto prodotto: prodotti){
totale += prodotto.getTotale();
}
txtImportoTotale.setText(Double.toString(totale));
}//GEN-LAST:event_btnImportoTotaleActionPerformed
private double leggiCampo(javax.swing.JTextField campo){
double valoreCampo = -1;