Input prodotto singolo
This commit is contained in:
@@ -23,13 +23,121 @@
|
|||||||
<Layout>
|
<Layout>
|
||||||
<DimensionLayout dim="0">
|
<DimensionLayout dim="0">
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||||
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<Component id="lblPrezzo" max="32767" attributes="0"/>
|
||||||
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblQuantita" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<Component id="btnPrezzo" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
|
<Component id="btnQuantita" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<Component id="txtPrezzo" min="-2" pref="109" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtQuantita" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="btnImportoTotale" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Group type="102" attributes="0">
|
||||||
|
<Component id="txtImportoTotale" pref="101" max="32767" attributes="0"/>
|
||||||
|
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
|
||||||
|
<Component id="btnAggiungi" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Component id="lblImportoTotale" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
<DimensionLayout dim="1">
|
<DimensionLayout dim="1">
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
<Group type="102" alignment="0" attributes="0">
|
||||||
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="lblPrezzo" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblQuantita" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblImportoTotale" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="txtPrezzo" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtQuantita" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtImportoTotale" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btnAggiungi" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="btnPrezzo" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btnQuantita" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btnImportoTotale" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace pref="23" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
<SubComponents>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblPrezzo">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Prezzo"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblQuantita">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Quantità"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblImportoTotale">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Importo totale"/>
|
||||||
|
</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">
|
||||||
|
<Properties>
|
||||||
|
<Property name="editable" type="boolean" value="false"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btnAggiungi">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Aggiungi"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAggiungiActionPerformed"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btnPrezzo">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Media prezzo"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btnQuantita">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Media quantità"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btnImportoTotale">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Tot. vendite"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package guivendite;
|
package guivendite;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Verde
|
* @author Verde
|
||||||
@@ -11,7 +15,7 @@ package guivendite;
|
|||||||
public class GUIVendite extends javax.swing.JFrame {
|
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 final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(GUIVendite.class.getName());
|
||||||
|
private static ArrayList<Prodotto> prodotti = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* Creates new form GUIVendite
|
* Creates new form GUIVendite
|
||||||
*/
|
*/
|
||||||
@@ -28,22 +32,139 @@ public class GUIVendite extends javax.swing.JFrame {
|
|||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void 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);
|
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());
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||||
getContentPane().setLayout(layout);
|
getContentPane().setLayout(layout);
|
||||||
layout.setHorizontalGroup(
|
layout.setHorizontalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
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.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
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();
|
pack();
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//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
|
* @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
|
// 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
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user