codice:
public class MainPanel extends JPanel implements PropertyChangeListener{
static int i =0,volta =0;
static Componenti_Swing.TableExample table;
String salva;
Vector rows,columns;
static JTable ricetteTabella;
JScrollPane jScrollPane1,jScrollPane2;
static String zuccheriC,grassiC,tipo,snglC, altresoluzioniC,elemento;
static JFormattedTextField zuccheri,grassi,sngl,altriSolidi;
static Double amount = 0.00,Diff =0.00,DifferenzaRip=0.00,Quantita = 100.00, sommaSNGL=0.00,sommaAltrisolidi,DifferenzaSom=0.00,Sngl=0.00,Zuccheri=0.00,PercentualeDif=0.00;
MyTableModel tableModel;
static Double Grassi=0.00,sommaZuccheri=0.00,zuccheriint,sommaQuantita=0.00,AltriSolidi=0.00,sommaGrassi=0.00;
static Double ZuccheriSom=0.00,GrassiSom=0.00, SnglSom=0.00, AltriSolidiSom=0.00,QuantitaSom=0.00;
static Double ZuccheriDif =0.00,GrassiDif=0.00,SnglDif=0.00,AltriSolidiDif=0.00,QuantitaDif=0.00;
Double ZuccheriRip=0.00, GrassiRip=0.00,SnglRip=0.00,AltriSolidiRip=0.00;
static JFormattedTextField quantitaRip,grassiRip,zuccheriRip,snglRip,altriSolidiRip,supportoRip,supporto,supportoDif,zuccheriDif, grassiDif,supportoSom,quantitaDif,quantitaSom,zuccheriSom,grassiSom,snglSom,altriSolidiSom,snglDif,altriSolidiDif;
Font fontTable;
static Double differenza;
static Double percZuccheri;
static Double somma =0.00;
boolean primoAccesso=false;
SplashScreen screen;
private DefaultListModel model = new DefaultListModel();
public MainPanel(){
ImageIcon myImage = new ImageIcon("immagini/concepimento-dieta-della-fertilita-coppa-di-gelato2.jpg");
SplashScreen screen = new SplashScreen(myImage);
screen.setLocationRelativeTo(null);
screen.setProgressMax(100);
screen.setScreenVisible(true);
for (int i = 0; i <= 100; i++)
{
for (long j=0; j<50000; ++j)
{
String poop = " " + (j + i);
}
screen.setProgress("Yo " +i, i);
}
Dimensione dimensioneComponenti = new Dimensione();
Toolkit t = Toolkit.getDefaultToolkit();
Dimension screenSize = t.getScreenSize();
double width = screenSize.getWidth() ;
double height= screenSize.getHeight() *0.9;
Dimension d2 = new Dimension();
d2.setSize(dimensioneComponenti.DimensionePanel());
this.setPreferredSize(d2);//dimensione Frame principale
Dimension dTabella = new Dimension();
dTabella.setSize(dimensioneComponenti.jScrollPane2());
Dimension dTable = new Dimension();
dTable.setSize(dimensioneComponenti.jScrollPane1());
//questa è la tabella dove verrà effettuato tutto il calcolo degli ingredienti
rows=new Vector();
tableModel = new MyTableModel();
// ricetteTabella = new JTable(new MyTableModel());
ricetteTabella = new JTable(tableModel);
ricetteTabella.setFont(fontTable);
ricetteTabella.setRowHeight(25);
ricetteTabella.setDropMode(DropMode.INSERT_ROWS);
jScrollPane2 = new javax.swing.JScrollPane();
jScrollPane2.setName("jScrollPane2");
jScrollPane2.setViewportView(ricetteTabella);
//ricetteTabella.setPreferredSize(dTabella);
jScrollPane2.setPreferredSize(dTabella);
jScrollPane2.getViewport().add(ricetteTabella);
jScrollPane2.setVisible(true);
Vector vettore = new Vector();//do nome alle colonne
vettore.add(new String("Ingrediente"));
table = new TableExample(v, vettore);
table.setRowHeight(25);
table.setFillsViewportHeight(true);
jScrollPane1 = new javax.swing.JScrollPane();
jScrollPane1.setName("jScrollPane1");
jScrollPane1.setViewportView(table);
jScrollPane1.setPreferredSize(dTable);
jScrollPane1.getViewport().add(table);
jScrollPane1.setVisible(true);
GridBagConstraints GBC = new GridBagConstraints();
Container CR = new Container();
GridBagLayout GBL = new GridBagLayout();
CR.setComponentOrientation(ComponentOrientation.UNKNOWN);
CR.setLayout(GBL);
this.add(CR);
GBC = new GridBagConstraints();
CR.add(jScrollPane2);
GBC.gridx=0;
GBC.gridy=0;
GBC.gridwidth=8;
GBC.gridheight=2;
GBC.insets.top=5;
GBC.insets.bottom=10;
GBC.insets.left=2;
GBC.insets.right=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(jScrollPane2,GBC);
GBC = new GridBagConstraints();
CR.add(jScrollPane1);
GBC.gridx=8;
GBC.gridy=0;
GBC.gridwidth=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(jScrollPane1,GBC);
LabelFormat lperc= new LabelFormat("in %");
LabelFormat lqua= new LabelFormat("Quantità");
LabelFormat lzuc= new LabelFormat("Zuccheri");
LabelFormat lgra= new LabelFormat("Grassi");
LabelFormat lsng= new LabelFormat("Sngl");
LabelFormat laltr= new LabelFormat("AltriSolidi");
GBC = new GridBagConstraints();
CR.add(lperc);
GBC.gridx=1;
GBC.gridy=2;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(lperc,GBC);
GBC = new GridBagConstraints();
CR.add(lqua);
GBC.gridx=2;
GBC.gridy=2;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(lqua,GBC);
GBC = new GridBagConstraints();
CR.add(lzuc);
GBC.gridx=3;
GBC.gridy=2;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(lzuc,GBC);
GBC = new GridBagConstraints();
CR.add(lgra);
GBC.gridx=4;
GBC.gridy=2;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(lgra,GBC);
GBC = new GridBagConstraints();
CR.add(lsng);
GBC.gridx=5;
GBC.gridy=2;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(lsng,GBC);
GBC = new GridBagConstraints();
CR.add(laltr);
GBC.gridx=6;
GBC.gridy=2;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(laltr,GBC);
t
Dimension dText = new Dimension();
dText.setSize(dimensioneComponenti.textMainPanel());
LabelFormat labelDifferenza = new LabelFormat("Quantità Mancanti: ");
supportoDif = new JFormattedTextField();
supportoDif.setValue(new Double(PercentualeDif));
supportoDif.setBackground(Color.red);
supportoDif.setPreferredSize(dText);
quantitaDif = new JFormattedTextField();
quantitaDif.setValue(new Double(QuantitaDif));
quantitaDif.setBackground(Color.red);
quantitaDif.addPropertyChangeListener("value", this);
quantitaDif.setPreferredSize(dText);
zuccheriDif = new JFormattedTextField();
zuccheriDif.setValue(new Double(ZuccheriDif));
zuccheriDif.setBackground(Color.red);
zuccheriDif.addPropertyChangeListener("value", this);
zuccheriDif.setPreferredSize(dText);
grassiDif = new JFormattedTextField();
grassiDif.setValue(new Double(GrassiDif));
grassiDif.setBackground(Color.red);
grassiDif.addPropertyChangeListener("value", this);
grassiDif.setPreferredSize(dText);
snglDif = new JFormattedTextField();
snglDif.setValue(new Double(SnglDif));
snglDif.setBackground(Color.red);
snglDif.addPropertyChangeListener("value", this);
snglDif.setPreferredSize(dText);
altriSolidiDif = new JFormattedTextField();
altriSolidiDif.setValue(new Double(AltriSolidiDif));
altriSolidiDif.setBackground(Color.red);
altriSolidiDif.addPropertyChangeListener("value", this);
altriSolidiDif.setPreferredSize(dText);
GBC = new GridBagConstraints();
CR.add(labelDifferenza);
GBC.gridx=0;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(labelDifferenza,GBC);
GBC = new GridBagConstraints();
CR.add(supportoDif);
GBC.gridx=1;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(supportoDif,GBC);
GBC = new GridBagConstraints();
CR.add(quantitaDif);
GBC.gridx=2;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(quantitaDif,GBC);
GBC = new GridBagConstraints();
CR.add(zuccheriDif);
GBC.gridx=3;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(zuccheriDif,GBC);
GBC = new GridBagConstraints();
CR.add(grassiDif);
GBC.gridx=4;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(grassiDif,GBC);
GBC = new GridBagConstraints();
CR.add(snglDif);
GBC.gridx=5;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(snglDif,GBC);
GBC = new GridBagConstraints();
CR.add(altriSolidiDif);
GBC.gridx=6;
GBC.gridy=3;
GBC.insets.top=5;
GBC.insets.left=10;
GBC.fill=GridBagConstraints.HORIZONTAL;
GBL.setConstraints(altriSolidiDif,GBC);
}
}//fine MainPanel
static class MyTableModel extends DefaultTableModel {
private static final Object[] columnNames = { "INGREDIENTI", "in %","Quantità","Zuccheri","Grassi","S.N.G.L.","Altri Solidi","Solidi Totale" ,"Costo" };
public MyTableModel() {
super(columnNames, 1); // 10 righe iniziali (vuote)
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
public Class getColumnClass(Float columnIndex) {
return Float.class; // Le due colonne sono numeri interi
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
super.setValueAt(aValue, rowIndex, columnIndex);
}
private static String getNextString(int count) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < 5; i++) {
buf.append(String.valueOf(count));
buf.append(",");
}
// remove last newline
buf.deleteCharAt(buf.length() - 1);
return buf.toString();
}
}
public void propertyChange(PropertyChangeEvent e) {
Object source = e.getSource();
if (source == zuccheri) {
Zuccheri = ((Number)zuccheri.getValue()).doubleValue();
zuccheriRip.setText(Double.toString(Zuccheri));
} else if (source == grassi) {
Grassi = ((Number)grassi.getValue()).doubleValue();
grassiRip.setText(Double.toString(Grassi));
} else if (source == sngl) {
Sngl = ((Number)sngl.getValue()).doubleValue();
snglRip.setText(Double.toString(Sngl));
}else if (source == altriSolidi) {
AltriSolidi = ((Number)altriSolidi.getValue()).doubleValue();
//altriSolidiRip.setText(Double.toString(amount));
altriSolidiRip.setValue(AltriSolidi);
}
}//fine metodo change property
}//fine classe MainPanel