package windowsBuilder;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.GridLayout;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTabbedPane;
import javax.swing.JEditorPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollBar;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import javax.swing.border.BevelBorder;
import java.awt.Frame;
import java.awt.Label;
import java.awt.SystemColor;
import java.awt.Font;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JLayeredPane;
import javax.swing.JSeparator;
import javax.swing.JTree;
import javax.swing.JProgressBar;
import java.awt.Color;
import javax.swing.JDesktopPane;
import javax.swing.JFormattedTextField;
import javax.swing.JList;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;
import java.awt.Canvas;
public class loperfidus implements ActionListener {
private JFrame frame;
private JTextField textnum;
private JTextField textdata;
private JTextField txtnome;
private JTextField txtcognome;
private JTextField txtsocietà;
private JTextField txtindirizzo;
private JTextField txtCAP;
private JTextField txtcittà;
private JTextField txtpi;
private JTextField txtcf;
private JTextField txttel;
private JTextField txttotgen;
private JProgressBar progressBar = new JProgressBar(0,100) ;
private JMenuBar barra = new JMenuBar();
public JButton btntotgen = new JButton("NUOVA FATTURA");
public JButton btnSalva = new JButton("Salva");
public JButton btnCarica = new JButton("Carica");
public final int N = 10;
public int[] numf = new int[N];
public int j = 0;
public int i = 0;
public int l = 0;
public String[] data = new String[N];
public String[] nome = new String[N];
public String[] cognome = new String[N];
public String[] indirizzo = new String[N];
public String[] società = new String[N];
public String[] PI = new String[N];
public String[] cf = new String[N];
public String[] città= new String[N];
public String[] tel= new String[N];
public String[] CAP = new String[N];
private JTextField txtdescrizione;
private JTextField txtpunitario;
private JTextField txtq;
private JTextField txtimporto;
private JTextField txtsconto;
private JTextField txtIVA;
public final int num = 10;
private int c = 0;
private int[][] q = new int[num][num];
private String[][] descrizione = new String[num][num];
private double[][] p_unitario = new double[num][num];
private double[][] iva = new double[num][num];
private double[][] sc = new double[num][num];
private double[][] importo = new double[num][num];
private double[] totgen = new double[num];
private JProgressBar progressBar_1 = new JProgressBar(0,100);
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
loperfidus window = new loperfidus();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public loperfidus() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("Fattura 1.2");
frame.setBounds(100, 100, 593, 486);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setJMenuBar(barra);
creaMenu();
JPanel panel = new JPanel();
panel.setBounds(373, 11, 196, 48);
frame.getContentPane().add(panel);
panel.setLayout(new GridLayout(2, 2));
JLabel lblNFattura = new JLabel("N. fattura");
panel.add(lblNFattura);
textnum = new JTextField();
panel.add(textnum);
textnum.setColumns(10);
JLabel lblData = new JLabel("Data");
panel.add(lblData);
textdata = new JTextField();
panel.add(textdata);
textdata.setColumns(10);
JPanel pnlcliente = new JPanel();
pnlcliente.setBounds(10, 70, 559, 104);
frame.getContentPane().add(pnlcliente);
pnlcliente.setLayout(null);
JLabel lblCliente = new JLabel("Cliente");
lblCliente.setFont(new Font("Comic Sans MS", Font.PLAIN, 13));
lblCliente.setBounds(10, 0, 71, 14);
pnlcliente.add(lblCliente);
JLabel lblNome = new JLabel("Nome");
lblNome.setBounds(10, 25, 46, 14);
pnlcliente.add(lblNome);
txtnome = new JTextField(20);
txtnome.setBounds(67, 22, 86, 20);
pnlcliente.add(txtnome);
txtnome.setColumns(10);
JLabel lblCognome = new JLabel("Cognome");
lblCognome.setBounds(10, 50, 46, 14);
pnlcliente.add(lblCognome);
txtcognome = new JTextField(20);
txtcognome.setBounds(67, 47, 86, 20);
pnlcliente.add(txtcognome);
txtcognome.setColumns(10);
JLabel lblSociet = new JLabel("Societ\u00E0");
lblSociet.setBounds(10, 75, 46, 14);
pnlcliente.add(lblSociet);
txtsocietà = new JTextField();
txtsocietà.setBounds(67, 72, 86, 20);
pnlcliente.add(txtsocietà);
txtsocietà.setColumns(10);
JLabel lblIndirizzo = new JLabel("Indirizzo");
lblIndirizzo.setBounds(163, 25, 46, 14);
pnlcliente.add(lblIndirizzo);
txtindirizzo = new JTextField();
txtindirizzo.setBounds(219, 22, 86, 20);
pnlcliente.add(txtindirizzo);
txtindirizzo.setColumns(10);
JLabel lblCap = new JLabel("CAP");
lblCap.setBounds(163, 50, 46, 14);
pnlcliente.add(lblCap);
txtCAP = new JTextField(5);
txtCAP.setBounds(219, 47, 86, 20);
pnlcliente.add(txtCAP);
txtCAP.setColumns(10);
JLabel lblCitt = new JLabel("Citt\u00E0");
lblCitt.setBounds(163, 75, 46, 14);
pnlcliente.add(lblCitt);
txtcittà = new JTextField(20);
txtcittà.setBounds(219, 72, 86, 20);
pnlcliente.add(txtcittà);
txtcittà.setColumns(10);
JLabel lblPiva = new JLabel("P.iva");
lblPiva.setBounds(315, 25, 46, 14);
pnlcliente.add(lblPiva);
txtpi = new JTextField(11);
txtpi.setBounds(371, 22, 86, 20);
pnlcliente.add(txtpi);
txtpi.setColumns(10);
JLabel lblCFiscale = new JLabel("C. fiscale");
lblCFiscale.setBounds(315, 50, 46, 14);
pnlcliente.add(lblCFiscale);
txtcf = new JTextField(16);
txtcf.setBounds(371, 47, 86, 20);
pnlcliente.add(txtcf);
txtcf.setColumns(10);
JLabel lblTel = new JLabel("Tel");
lblTel.setBounds(315, 75, 46, 14);
pnlcliente.add(lblTel);
txttel = new JTextField(13);
txttel.setBounds(371, 72, 86, 20);
pnlcliente.add(txttel);
txttel.setColumns(10);
btnSalva.addActionListener(this);
btnSalva.setBounds(467, 71, 89, 23);
pnlcliente.add(btnSalva);
btntotgen.addActionListener(this);
btntotgen.setBounds(54, 322, 132, 23);
frame.getContentPane().add(btntotgen);
txttotgen = new JTextField();
txttotgen.setBounds(227, 317, 229, 33);
frame.getContentPane().add(txttotgen);
txttotgen.setColumns(10);
txttotgen.setEditable(false);
progressBar.setBounds(118, 370, 459, 14);
frame.getContentPane().add(progressBar);
JSeparator separator = new JSeparator();
separator.setBounds(10, 195, 559, 2);
frame.getContentPane().add(separator);
JLabel lblMemoriDisponibile = new JLabel("Clienti");
lblMemoriDisponibile.setFont(new Font("Comic Sans MS", Font.PLAIN, 11));
lblMemoriDisponibile.setBounds(0, 370, 121, 14);
frame.getContentPane().add(lblMemoriDisponibile);
JLabel lblQuantit = new JLabel("Quantit\u00E0");
lblQuantit.setBounds(10, 224, 46, 14);
frame.getContentPane().add(lblQuantit);
JLabel lblDescrizione = new JLabel("Descrizione");
lblDescrizione.setBounds(75, 224, 177, 14);
frame.getContentPane().add(lblDescrizione);
JLabel lblPunitario = new JLabel("P.unitario");
lblPunitario.setBounds(262, 224, 46, 14);
frame.getContentPane().add(lblPunitario);
JLabel lblIva = new JLabel("IVA");
lblIva.setBounds(332, 224, 46, 14);
frame.getContentPane().add(lblIva);
JLabel lblSconto = new JLabel("Sconto");
lblSconto.setBounds(398, 224, 46, 14);
frame.getContentPane().add(lblSconto);
JLabel lblImporto = new JLabel("Importo");
lblImporto.setBounds(485, 224, 46, 14);
frame.getContentPane().add(lblImporto);
txtdescrizione = new JTextField();
txtdescrizione.setBounds(75, 243, 169, 20);
frame.getContentPane().add(txtdescrizione);
txtdescrizione.setColumns(10);
txtpunitario = new JTextField();
txtpunitario.setBounds(255, 243, 70, 20);
frame.getContentPane().add(txtpunitario);
txtpunitario.setColumns(10);
txtq = new JTextField();
txtq.setBounds(10, 243, 55, 20);
frame.getContentPane().add(txtq);
txtq.setColumns(10);
txtimporto = new JTextField();
txtimporto.setBounds(481, 243, 86, 20);
frame.getContentPane().add(txtimporto);
txtimporto.setColumns(10);
txtimporto.setEditable(false);
txtsconto = new JTextField();
txtsconto.setBounds(385, 243, 86, 20);
frame.getContentPane().add(txtsconto);
txtsconto.setColumns(10);
txtIVA = new JTextField();
txtIVA.setBounds(332, 243, 46, 20);
frame.getContentPane().add(txtIVA);
txtIVA.setColumns(10);
btnCarica.addActionListener(this);
btnCarica.setBounds(485, 284, 89, 23);
frame.getContentPane().add(btnCarica);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(10, 70, 132, -7);
frame.getContentPane().add(separator_1);
progressBar_1.setBounds(118, 391, 459, 14);
frame.getContentPane().add(progressBar_1);
JLabel lblProdotti = new JLabel("Prodotti ");
lblProdotti.setBounds(0, 391, 46, 14);
frame.getContentPane().add(lblProdotti);
}
public JMenuBar creaMenu(){
JMenu menu2;
JMenuItem voce2;
menu2 = new JMenu("Cliente");
menu2.setMnemonic(KeyEvent.VK_C);
barra.add(menu2);
voce2 = new JMenuItem("1."+ nome[0] + cognome[0]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("2."+ nome[1] + cognome[1]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("3."+ nome[2] + cognome[2]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("4."+ nome[3] + cognome[3]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("5."+ nome[4] + cognome[4]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("6."+ nome[5] + cognome[5]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("7."+ nome[6] + cognome[6]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("8."+ nome[7] + cognome[7]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("9."+ nome[8] + cognome[8]);
voce2.addActionListener(this);
menu2.add(voce2);
voce2 = new JMenuItem("10."+ nome[9] + cognome[9]);
voce2.addActionListener(this);
menu2.add(voce2);
return barra;
}
public void Salva(){
try{
if(j<N){
String str = textnum.getText();
numf[j] = Integer.valueOf(str).intValue();
data[j] = textdata.getText();
nome[j] = txtnome.getText();
cognome[j] = txtcognome.getText();
indirizzo[j] = txtsocietà.getText();
società[j] = txtindirizzo.getText();
PI[j] = txtpi.getText();
cf[j] = txtcf.getText();
città[j] = txtcittà.getText();
tel[j] = txttel.getText();
CAP[j] = txtCAP.getText();
i = i + 10;
progressBar.setValue(i);
j++;
}//while
}catch(Exception ex){
}//catch
}//salva()
public void Carica(){
try{
if(l<N){
String str = txtq.getText();
q[j][l] = Integer.valueOf(str).intValue();
descrizione[j][l] = txtdescrizione.getText();
str = txtpunitario.getText();
p_unitario[j][l] = Double.valueOf(str).doubleValue();
str = txtIVA.getText();
iva[j][l] = Double.valueOf(str).doubleValue();
str = txtsconto.getText();
sc[j][l] = Double.valueOf(str).doubleValue();
double imp2 = q[j][l]*p_unitario[j][l];
double sc2 = imp2*sc[j][l]/100 ;
imp2 = imp2 - sc2;
importo[j][l] = imp2 + (imp2)*iva[j][l]/100;
txtimporto.setText(importo[j][l] + "€");
totgen[j] = totgen[j]+ importo[j][l];
txttotgen.setText(" "+ totgen[j] + "€");
txtdescrizione.setText("");
txtpunitario.setText("");
txtq.setText("");
txtsconto.setText("");
txtIVA.setText("");
l++;
c = c + 10;
progressBar_1.setValue(c);
}
}catch(Exception ex){
//JOPTIONPANE ......
}//catch()
}//Carica()
public void newfat(){
try{
textnum.setText("");
textdata.setText("");
txtnome.setText("");
txtcognome.setText("");
txtsocietà.setText("");
txtindirizzo.setText("");
txtCAP.setText("");
txtcittà.setText("");
txtpi.setText("");
txtcf.setText("");
txttel.setText("");
txttotgen.setText("");
txtdescrizione.setText("");
txtpunitario.setText("");
txtq.setText("");
txtimporto.setText("");
txtsconto.setText("");
txtIVA.setText("");
l = 0;
c = 0;
progressBar_1.setValue(c);
}catch(Exception ex){
//JOptionPane
}
}//newfat
public void actionPerformed(ActionEvent e){
String bottone = e.getActionCommand();
if(bottone.equals("Salva")) Salva();
if(bottone.equals("Carica")) Carica() ;
if(bottone.equals("NUOVA FATTURA")) newfat();
}
}