package lt.ktu.diet;
/**
 * Saulius Sinkevičius iki 2010-03-28
 * 1. Prie kiekvieno produkto ir patiekalo pridėtas naujas parametras - kiek skysčių ten yra gramais;
 * 2. Įvestas naujas apribojimas - skysčiams. Per parą žmogui rekomenduojama suvartoti tam tikrą kiekį skysčių;
 * 3. Įdėtas skysčių parametro redagavimas ir naujo produkto/patiekalo su šiuo parametru kurimas;
 * 4. Nuimti dirbtiniai kilogramų apribojimai produktams;
 * 5. Suvienodinti apribojimai, keli buvo skaičiuojami be savaitės įverčio;
 * 6. Rezultatų lentelėje uždėti matavimo vienetai;
 * 7. index.html pataisytas komentaras apie grožį, nes tai nėra procentinė išraiška;
 * 8. Skonis procentinė išraiška, todėl [1;10] skalė išplėsta iki [0;10].
 */
/** eguogis
 * Sutvarkiau problemas su virsutinem ir apatinem ribom.
 * Faile Constants dabar galima nustatyti apatines ir virsutines toleravimo ribas.
 * Pataisyta optimizavimo formule.
 * Blogai veikdavo, kai produktai buvo atrenkami pagal skoni. Rezultatai budavo atrenkami ne is to masyvo.
 * Radau bugiuka solve.java, del kurio kartais mesdavo ArrayOutOfBoundsException
 * Ziureti TODO. Jei solve.java naudojamas ir kitose programose, reiketu pakeisti.
 * Iskeliau konstantas i atskira klase.
 * Pravaliau koda, bet dar reiktu daug valymo... 
 * No offence, bet UI ir duomenu ivedimas daryti ne programuotojo, arba programuotojo be realios darbo patirties :)
 */
/**********cmbbxIAddTaste*********************************************************************
 * Dietos uzdavinio sprendimo klase
 * *****************************************************
 * Pataisymus iki 2007 01 24 atliko MII doktorantai: Rasa Karbauskaite, Alma Muolyte, Ernestas Filatovas
 * Pradinis kodas paimtas is "dieta_inga".
 * 
 * Pakeitimai:
 * 1. Atsakymuose pateikiant dieta, isvedamas tik vienas patiekalas to paties pavadinimo,
 *   o anksciau budavo ju daugiau (pvz., 12 rugstiniu sriubu)
 * 2. Isvedant rezulatatus, skaicai pateikiami dvieju skaiciu po kablelio tikslumu. (pvz., 12,56)
 * Tuo tikslu buvo sukurta atskira klase "DoubleToString.java" .
 * 3. Isvedant rezulatatus, dieta sudarantys elemntai rodomi su ju matavimo vienetais (pvz., Mg, g, kcal)
 * 4. Pataisėme tikslo funkciją. 91 formulėje (iš Jūsų skaidrių) buvo praleistas koeficientas b1 (reikalingas kalorijų kiekis).
 * 5. Testuojant skaičiavimo paklaida negali būti lygi 0. Ji turi būti tik labai labai artima 0, pvz.: 0.0001.
 * 
 * 
 * 
 * ***********************************************************
 * -----------------------------------------------------------------------------
 * Atliko: Vidas Razmislevicius IT-3/2,Inga Liutkeviciute IT-3/1 1/1 2006
 * Pradinis kodas paimtas is: https://pilis.if.ktu.lt/~jmockus/dietadoviltis/DietaV4.zip
 *
 *  1. Padaryta, kad butu galima pasirinkti kokiam zmogui bus formuojama dieta:
 *    a) pagal amziu (atskirai vaikams), pagal lyti, pagal fizini aktyvuma
 *    b) galima pasirinkti papildomas savybes - ligos, moterims nestumas ir vaiko zindymo laikotarpis
 * 2. Iskeltas paklaidos koef., dabar ji galima redaguoti. Paklaida - tai kiek
 *     leidziama pazeisti nustatytus apribojimus: ai-p*ai <= xi <= ai+p*ai - tai suteikia didesne sprendiniu aibe
 *     Buvo ivesta tikriausiai todel, kad grieztai lankantis apribojimu, nebudavo gaunamas joks prendinys
 * 3. Pakeista tikslo funkcija. Pridedas maisto ivairumo parametras (91 form., sliden.pdf, 55p) 
 * 4. Sukurti papildomi maisto produktu-patiekalu sarasai:
 *   a) duom.txt - bendras sarasas
 *   b) duomv.txt - maistas vegetarams
 
 * Pradinis kodas: *****
 * is http://soften.ktu.lt/~mockus/dietalast/contdietalast.html
 * -----------------------------------------------------------------------------
 * Komentarai ir pakeitimai: Marijus Doviltis IFM-0/1 2005
 *
 * Atlikta:
 *  1. Kodas papildytas komentarais, sutvarkyti pavadinimai,kad atspindetu tuos
 *     duomenis kurie imami is lenteles o ne Mg zymetu Na ir pan. Taip pat buvo 
 *     naudojamas Cl vietoj J (Chloras vietoj Jodo), Cl nera normose, be to jis 
 *     nera is tu elementu kurie paprastai ivertinami. Mano nuomone rusiskoje
 *     medziagoje Cl taip pat panaudotas vietoje J, juo lab kad sutikrinus 
 *     duomenis su http://soften.ktu.lt/~mockus/dietalagu/dieta-prods.txt
 *     cl kiekis atitinka J kieki. 
 *  2. Perziureti skaiciavimai, pasalinti nereikalingi, painus ir neaisku kam
 *     skirti perskaiciavimai is vieno dydzio i kita o paskui vel atgal.
 *  3. Is naujo isversta rusiska medziaga, dalis patikrinta ir pakoreguota
 *     pagal kitus saltinius
 *  4. Perdelioti duomenu laukai applete, dalis ju sugrupuota. Tai turetu 
 *     palengvinti tolimesnes modifikacijas jei bus pridedami apribojimai,
 *     be to taip patogiau naudotis.
 *  5. Patiekalas yra neskaidomas (t.y. jis gali buti: 0, 1,2... , bet ne 0.0002
 *     ar pan. Be to,patiekalo maistiniai elementai neskaiciuojami kilogramais
 *     ty ne dauginti is 10
 *  6. Perkelta galimybe is siu metu darbo, kad itrauktu tik tuos produktus kuriu
 *     skonis atitinka pasirinkta su intervalu [pasirinkas:10]
 *     Bet sitas pasirinkimas atliekamas atskiru parametru o ne bendru kaip 
 *     buvo padaryta kolegu.
 *  7. Sutvarkyta optimizavimo formule pagal teorija, kad
 atitiktu realius 
 *     rezultatus. 
 *  8. Isvedami visi optimizavimo parametrai. Kartais pranesimas - "Virsijote
 *     rekomenduojama norma" gaunamas ,nes kelis kartus virsyjama norma pagal 
 *     vitaminus ar mineralus.
 *  9. Dabartiniai skaiciavimai atliekami su 12 grieztu ribojimu (ty virsutine 
 *     ir apatine ribos nurodytos 12 dedamuju) visi kiti apriboti is apacios.
 *     Grieztai apribota: Cal,Baltymai,Riebalai,Angliavandelniai
 *                        vitaminai:A,B1,B2,B3,B6,B12,PP;
 *                        mikroelementai: Ca,S;
 *     Apribojimas is apacios (ty ne maziau negu reikia) sukuria tarsi laisves 
 *     laipsnius. Is apacios apriboti yra:
 *                        vitaminai: C,E;
 *                        mikroelementai: P(Fosforas),Na;
 * 10.(papildymai)Teorine formule pakoreguota(po konsultaciju su M.Patasiumi
 *    prieita isvados kad dydziai prie x ieina tiesiogiai (ty ci-si+grozis*ai1),
 *    o grozis*bi1 pridedamas prie visu patiekalu ir kaip konstanta tik pakelia 
 *    dydzius bet nuo to sprendiniai nesikeicia.
 * 11.Grozio faktorius ivedamas nebe indeksais bet laisvu skaičiumi.
 *****
 * Dar reikia atlikti (pasiulymai kitiem metam):
 * 1. Patikslinti duomenis lenteleje ir ja papildyti
 * 2. Kadangi dienos normos yra atskirose lentelese, jos priklauso ne tik nuo
 *    mases, bet ir nuo amziaus, gyvenimo budo. Vartotojui patogu butu siuos 
 *    duomenis gauti migtuko paspaudimu ir pasirinkti norimus (kvepia dideliu
 *    programavimu)
 * ****************************************************************************
 * Naudingi parametrai:
 * Nurodant elemento pozicija applete naudojamos koordinates (x1,y1, delta x,delta y)
 * (x1,y1 - virsutinis kairysis taskas,delta x,delta y-dydis)
 * x dideja nuo kaires, y dideja nuo virsaus
 *------------------------------------------------
 **/

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import lp.lprec;
import lp.solve;
import lt.ktu.diet.common.Constants;
import lt.ktu.diet.common.Converter;

import com.symantec.itools.javax.swing.borders.LineBorder;
import com.symantec.itools.javax.swing.models.StringComboBoxModel;
import com.symantec.itools.javax.swing.models.StringTableModel;
import com.symantec.itools.lang.Context;
import java.io.*;

public class Dieta extends JApplet
{

	private static final long serialVersionUID = 1L;

	//Konstantos. Neisiaiskines ka daro - nekisk nagu
    static final short LE = 0;
    static final short GE = 2;

    int productCount; // pagrindinio produktu saraso dydis
    int activProdCnt; //produktu skaicius kurie itraukiami i skaiciavimus
    Product produktai[]; //pagrindinis produktu sarasas
    Product prodActiv[]; //aktyviu produktu sarasas
    Product produktai1[];// laikinas sarasas

    //kiti kintamieji,vaizdo elementai ir tt   
    private boolean duomenuKlaida;
    private String failas;
    private JDialog D;
    private JLabel lblFailas;
    private JTextField txtfldFailas;
    private JButton btnOK;
    private JTabbedPane tbdpnlBendras;
    private JPanel pnlDuomenys;
    private JScrollPane scrlpnLentele;
    private JTable tblLentele;
    private JLabel lblLentelesPav;
    private JLabel lblRedagavimas;
    private JLabel lblName;
    private JTextField txtfldName;
    private JLabel lblPrice;
    private JTextField txtfldPrice;
    private JLabel lblCalories;
    private JTextField txtfldCalories;
    private JLabel lblProteins;
    private JTextField txtfldProteins;
    private JLabel lblFats;
    private JTextField txtfldFats;
    private JLabel lblCarbohydrates;
    private JTextField txtfldCarbohydrates;    
    private JLabel lblFluids;
    private JTextField txtfldFluids;        
    private JLabel lblTaste;
    private JComboBox cmbbxTaste;
    private JButton btnLoad;
    private JButton btnNew;
    private JButton btnUpdate;
    private JButton btnNext1;
    private JButton btnDelete;
    private JCheckBox chkbxDish;
    private JCheckBox chkbxDay;
    private JLabel lblDish;
    private JLabel lblDay;
    private JLabel JLabel5;
    private JLabel JLabel6;
    private JLabel JLabel7;
    private JLabel JLabel8;
    private JLabel JLabelB22; 
    private JLabel JLabelB33;
    private JLabel JLabelB66;
    private JLabel JLabelB122;
    private JLabel JLabelPP; 
    private JLabel JLabelCa2;
    private JLabel JLabelNa2;
    private JLabel JLabelS2; 
    private JLabel JLabelP2; 
    private JLabel JLabelJ2;
    private JTextField txtfldVitaminC;
    private JTextField txtfldVitaminA;
    private JTextField txtfldMineralCa;
    private JTextField txtfldMineralNa;
    private JPanel pnlPageidavimai;
    private JTextField txtfldWeight;
    private JLabel lblWeight;
    private JButton btnNext2;
    private JComboBox cmbbxOptimization;
    private JLabel lblOptimization;
    private JTextField txtfldVitaB2; 
    private JTextField txtfldVitaB3; 
    private JTextField txtfldVitaB6;  
    private JTextField txtfldVitaB12;  
    private JTextField txtfldVitaPP;  
    private JTextField txtfldMCA;   
    private JTextField txtfldMNa;  
    private JTextField txtfldMS;  
    private JTextField txtfldMP;  
    private JTextField txtfldMJ;  
    private JLabel lblImportance;
    private JTextField cmbbxImportance;
    private JLabel JLabel9;
    private JLabel JLabel10;
    private JLabel JLabel11;
    private JLabel JLabel12;
    private JLabel JLabel13;
    private JLabel JLabel14;
    private JLabel JLabel15;
    private JPanel pnlRezultatai;
    private JScrollPane JScrollPane1;
    private JTable JTable1;
    private JLabel JLabel1;
    private JLabel JLabel2;
    private JLabel JLabel3;
    private JLabel JLabel4;
    private JLabel lblCaloriesTotal;
    private JLabel lblProteinsTotal;
    private JLabel lblFatsTotal;
    private JLabel lblCarbohydratesTotal;

    private JLabel lblPriceTTlbl;
    private JLabel lblPriceTotal;
    private JLabel lblPriceTTlblS;
    private JLabel lblPriceTotalS;

    private JLabel lblVitATotal;
    private JLabel lblVitCTotal;
    private JLabel lblVitB1Total;
    private JLabel lblVitB2Total;
    private JLabel lblVitB3Total;
    private JLabel lblVitB6Total;
    private JLabel lblVitB12Total;
    private JLabel lblVitETotal;
    private JLabel lblVitPPTotal;
    private JLabel lblMinCaTotal;
    private JLabel lblMinNaTotal;
    private JLabel lblMinSTotal;
    private JLabel lblMinPTotal;
    private JLabel lblMinJTotal;
    private JLabel lblMinLiquidTotal;
    
    private JLabel lblVitATTlbl;
    private JLabel lblVitB1TTlbl;
    private JLabel lblVitB2TTlbl;
    private JLabel lblVitB3TTlbl;
    private JLabel lblVitB6TTlbl;
    private JLabel lblVitB12TTlbl;
    private JLabel lblVitCTTlbl;
    private JLabel lblVitETTlbl;
    private JLabel lblVitPPTTlbl;
    private JLabel lblMinCaTTlbl;
    private JLabel lblMinNaTTlbl;
    private JLabel lblMinSTTlbl;
    private JLabel lblMinPTTlbl;
    private JLabel lblMinJTTlbl;
    private JLabel lblMinLiquidTTlbl;

    private StringTableModel tblmdlLentele;

    private StringComboBoxModel cmbbxmdlTaste;
    private StringComboBoxModel cmbbxmdlProteinsW;
    private StringComboBoxModel cmbbxmdlfatsW;
    private StringComboBoxModel cmbbxmdlCarbohydratesW;
    private StringComboBoxModel cmbbxmdlCaloriesW;
    private LineBorder lineBorder1;
    private StringTableModel tblmdlRezultatai;
    private StringComboBoxModel cmbbxmdlOptimize;
    private StringComboBoxModel cmbbxmdlBias;
    private JLabel lblStatus;
    private StringComboBoxModel cmbbxmdlITaste;
    private StringComboBoxModel cmbbxmdlIPrice;
    private StringComboBoxModel cmbbxmdlImportance;
    
    private JTextField ReikiaAngl;
    private JTextField ReikiaBalt;
    private JTextField ReikiaFosf;
    private JTextField ReikiaKal;
    private JTextField ReikiaKalc;
    private JTextField ReikiaNatr;
    private JTextField ReikiaRieb;
    private JTextField ReikiaSer;
    private JTextField ReikiaJ;
    private JTextField ReikiaLiquid;
    
    private JTextField ReikiaVitA;
    private JTextField ReikiaVitB1;
    private JTextField ReikiaVitB2;
    private JTextField ReikiaVitB3;
    private JTextField ReikiaVitB6;
    private JTextField ReikiaVitB12;    
    private JTextField ReikiaVitC;
    private JTextField ReikiaVitE;
    private JTextField ReikiaVitPP;    
    
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JLabel jLabel4;
    private JLabel jLabel5;
    private JLabel jLabel6;
    private JLabel jLabel7;
    private JLabel jLabel8;
    private JLabel jLabel9;
    private JLabel jLabel10;
    private JLabel jLabel11;
    private JLabel jLabel12;
    private JLabel jLabel13;
    private JLabel jLabel14;
    private JLabel jLabel15;
    private JLabel jLabel16;
    private JLabel jLabel17;
    private JLabel jLabel18;
    private JLabel jLabel19;
    private JLabel jLabel20; 
    private JLabel jLabel21;    
    private JLabel jLabel22;   
    private JLabel jLabel23;

    JLabel JLabelAddOnTaste;
    JComboBox cmbbxIAddTaste;
	/*
	*  ----------<< Laurynas Simaitis >>-------------------
	* nauji 
	*/
	private JTextField jReikalavimuTekstas;	// nauju reikalavimu idejimui (paste)
	private JTextField jPaklaida;			// skaiciavimo paklaidai nustatyti (esant standartiniai paklaida kartais kartais neduoda rezultatu)
	private JTextField jIvairove;			// maisto ivairoves koef.
	private JPanel jpnlIkrautiReikalavimus; // panele nauju reikalavimu ikrovimui
	private JButton jIkrautiReikalavimus;	// Ikrauna reikalavimus is teksto lauko "jReikalavimaiVisi"
	private String dienosReikalavimai[] ;	// masyvas, saugauntis dienos reikalavimus tekstiniame formate
	private String papildomiReikalavimai_V[]; // papildomo reikalavimai, esant papildomoms salygoms: nestumas, zindymas, ivairios ligos - duomenys vyrams
	private String papildomiReikalavimai_M[]; // papildomo reikalavimai, esant papildomoms salygoms: nestumas, zindymas, ivairios ligos - duomenys moterims
	private JRadioButton jrbtVyras;			// radio mygtukas, pasirenkant vyro tipa
	private JRadioButton jrbtMoretis;		// radio mygtukas, pasirenkant moteris tipa
	private JRadioButton jrbtVaikas;		// radio mygtukas, pasirenkant vaiko tipa
	private ButtonGroup jrbtgrTipai;		// radio mydtuku grupe
	private JCheckBox jchbPapildimai;		// papildomu reikalavimai, esant nėštumui, ligos atveju arba kitos sąlygos
	private JComboBox jcbPapildomosSalygos_V; // papildomu salygu pasirinkimas
	private JComboBox jcbPapildomosSalygos_M; // papildomu salygu pasirinkimas
	private JButton jbtnPasirinkimas;		// ikrauti pageidavimus ir pasirikomo
	private JButton jbtnTekstas;			// ikrauti pageidavimus is teksto
	private JComboBox cmbbxAktyvumas;		// automatiniam pageidavimu ikrovimui
	private JComboBox cmbbxAmzius;			// automatiniam pageidavimu ikrovimui
	private JComboBox cmbbxVaikoAmzius;		// automatiniam pageidavimu ikrovimui
	private JCheckBox chkbxPapildoma;		// pazymejimas, ar reikia iskaiciuoti papildomus pageidavimus
	private JLabel jLabelAktyvumas;
	private JLabel jLabelAmzius;
	private JLabel jLabelPapildoma;			
	private JLabel jLabelPaklaida;
	private JLabel jLabelIvairovesIvedimas;	
	private JLabel jLabelIvairovesSprendimas;
	private JLabel jLabelIvairovesSprendimas2;
	private String sPavPapildomi_V[];				// papildimu reikalavimu pavadinimu masyvas (combobox'ui); vyrams
	private String sPavPapildomi_M[];				// papildimu reikalavimu pavadinimu masyvas (combobox'ui); moterims
	private JTextField tfldPapildomi;		// papildomu reikalavimu pavaizdavimui
	private Double fMaistoIvairumas;		// kriterijus, ivertinantis maisto ivairuma
	

//cal  balt  rieb angl  Ca   f   na   J  c   A   e  b1  b2  b6  PP b12 skysčiai
																		//aktyvumas,amzius,svoris
	private String pageidavimaiStandartiniai[] = {
" 41.21 2.58 0.69 6.18 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 17 3 2000",  	// (0) 1.5V19-34 70
" 38.94 2.43 0.65 5.84 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 17 3 2000",  // (1) 1.5V19-34 80
" 38.79 2.42 0.65 5.82 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 17 3 2000",  // (2) 1.5V35-49 70
" 36.75 2.29 0.61 5.51 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 17 3 2000",  	// (3) 1.5V35-49 80
" 36.39 2.27 0.61 5.46 1200 900 1500 40 60 0.90 10 1.5 1.7 1.4 17 3 2000",  // (4) 1.5V50-64 70
" 34.65 2.17 0.58 5.20 1200 900 1500 40 60 0.90 10 1.5 1.7 1.4 17 3 2000",  // (5) 1.5V50-64 80
" 41.16 2.57 0.69 6.17 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 16 3 2000",  // (6) 1.5M19-34 55
" 37.22 2.33 0.62 5.58 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 16 3 2000",  // (7) 1.5M19-34 65
" 38.96 2.44 0.65 5.84 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 16 3 2000",  // (8) 1.5M35-49 55
" 35.40 2.12 0.59 5.31 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 16 3 2000",  // (9) 1.5M35-49 65
" 36.85 2.30 0.61 5.53 1200 900 1500 40 60 0.70 10 1.3 1.4 1.2 16 3 2000",  // (10) 1.5M50-64 55
" 33.62 2.10 0.56 5.04 1200 900 1500 40 60 0.70 10 1.3 1.4 1.2 16 3 2000",  // (11) 1.5M50-64 65
" 44.23 2.89 0.77 6.93 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 18 3 2000",  // (12) 1.7V19-34 70
" 43.64 2.73 0.73 6.55 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 18 3 2000",  // (13) 1.7V19-34 80
" 50.60 3.16 0.84 7.59 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 18 3 2000",  // (14) 1.7V35-49 70
" 42.20 2.64 0.70 6.33 1000 900 1500 40 60 0.90 10 1.5 1.7 1.4 18 3 2000",  // (15) 1.7V35-49 80
" 35.00 2.19 0.58 5.25 1200 900 1500 40 60 0.90 10 1.5 1.7 1.4 18 3 2000",  // (16) 1.7V50-64 70
" 38.85 2.43 0.65 5.83 1200 900 1500 40 60 0.90 10 1.5 1.7 1.4 18 3 2000",  	// (17) 1.7V50-64 80
" 46.13 2.88 0.77 6.92 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 17 3 2000",  // (18) 1.7M19-34 55
" 41.75 2.61 0.70 6.26 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 17 3 2000",  	// (19) 1.7M19-34 65
" 43.68 2.73 0.73 6.55 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 17 3 2000",  // (20) 1.7M35-49 55
" 39.68 2.48 0.66 5.90 1000 900 1500 40 60 0.70 10 1.3 1.4 1.2 17 3 2000",  // (21) 1.7M35-49 65
" 41.32 2.58 0.69 6.20 1200 900 1500 40 60 0.70 10 1.3 1.4 1.2 17 3 2000",  // (22) 1.7M50-64 55
" 36.78 2.30 0.61 5.12 1200 900 1500 40 60 0.70 10 1.3 1.4 1.2 17 3 2000",  // (23) 1.7M50-64 65
" 54.98 3.44 0.92 8.25 1000 900 1500 40 60 0.90 10 1.7 1.7 1.5 19 3 2000",  // (24) 2.0V19-34 70
" 51.89 3.24 0.86 7.78 1000 900 1500 40 60 0.90 10 1.7 1.7 1.5 19 3 2000",  // (25) 2.0V19-34 80
" 51.68 3.23 0.87 7.75 1000 900 1500 40 60 0.90 10 1.7 1.7 1.5 19 3 2000",  	// (26) 2.0V35-49 70
" 48.99 3.06 0.82 7.35 1000 900 1500 40 60 0.90 10 1.7 1.7 1.5 19 3 2000",  // (27) 2.0V35-49 80
" 48.48 3.03 0.81 7.27 1200 900 1500 40 60 0.90 10 1.7 1.7 1.5 19 3 2000",  // (28) 2.0V50-64 70
" 46.21 2.89 0.77 6.93 1200 900 1500 40 60 0.90 10 1.7 1.7 1.5 19 3 2000",  // (29) 2.0V50-64 80
" 54.85 3.43 0.91 8.23 1000 900 1500 40 60 0.70 10 1.6 1.4 1.5 18 3 2000",  	// (30) 2.0M19-34 55
" 49.65 3.10 0.83 7.45 1000 900 1500 40 60 0.70 10 1.6 1.4 1.3 18 3 2000",  // (31) 2.0M19-34 65
" 51.95 3.25 0.87 7.79 1000 900 1500 40 60 0.70 10 1.6 1.4 1.3 18 3 2000",  	// (32) 2.0M35-49 55
" 47.19 2.95 0.79 7.08 1000 900 1500 40 60 0.70 10 1.6 1.4 1.3 18 3 2000",  // (33) 2.0M35-49 65
" 49.14 3.07 0.82 7.37 1200 900 1500 40 60 0.70 10 1.6 1.4 1.3 18 3 2000",  // (34) 2.0M50-64 55
" 44.82 2.80 0.75 6.72 1200 900 1500 40 60 0.70 10 1.6 1.4 1.3 18 3 2000",  	// (35) 2.0M50-64 65
" 59.97 3.75 1.00 9.00 1000 900 1500 40 60 0.90 10 1.9 1.7 1.6 20 3 2000",  // (36) 2.2V19-34 70
" 56.60 3.54 0.94 8.49 1000 900 1500 40 60 0.90 10 1.9 1.7 1.6 20 3 2000",  // (37) 2.2V19-34 80
" 56.37 3.52 0.94 8.46 1000 900 1500 40 60 0.90 10 1.9 1.7 1.6 20 3 2000",  // (38) 2.2V35-49 70
" 53.45 3.34 0.89 8.02 1000 900 1500 40 60 0.90 10 1.9 1.7 1.6 20 3 2000",  // (39) 2.2V35-49 80
" 52.89 3.31 0.88 7.93 1200 900 1500 40 60 0.90 10 1.9 1.7 1.6 20 3 2000",  // (40) 2.2V50-64 70
" 50.40 3.15 0.84 7.56 1200 900 1500 40 60 0.90 10 1.9 1.7 1.6 20 3 2000",  // (41) 2.2V50-64 80
" 59.84 3.74 1.00 8.98 1000 900 1500 40 60 0.70 10 1.7 1.4 1.5 19 3 2000",  // (42) 2.2M19-34 55
" 54.16 3.39 0.90 8.12 1000 900 1500 40 60 0.70 10 1.7 1.4 1.5 19 3 2000",  	// (43) 2.2M19-34 65
" 56.67 3.54 0.94 8.50 1000 900 1500 40 60 0.70 10 1.7 1.4 1.5 19 3 2000",  // (44) 2.2M35-49 55
" 51.48 3.22 0.86 7.72 1000 900 1500 40 60 0.70 10 1.7 1.4 1.5 19 3 2000",  // (45) 2.2M35-49 65
" 53.61 3.35 0.89 8.04 1200 900 1500 40 60 0.70 10 1.7 1.4 1.5 19 3 2000",  	// (46) 2.2M50-64 55
" 48.89 3.06 0.81 7.33 1200 900 1500 40 60 0.70 10 1.7 1.4 1.5 19 3 2000",  // (47) 2.2M50-64 65
" 1400 70 31 210 500 800 1500 20 40 0.40 5 0.7 0.8 0.9 9 2 1000",  			// (48) -1 - 3 m. 
" 1700 85 38 255 800 800 1500 20 45 0.50 6 0.9 1 1.0 11 2.5 1500",  			// (49) -4 - 6 m. 
" 2030 102 45 305 900 800 1500 20 45 0.60 7 1.1 1.4 1.1 13 3 1700",  		// (50) -7 - 10 m. 
" 2420 121 54 363 1300 1200 1500 30 50 0.70 8 1.2 1.6 1.2 15 3 1800",  		// (51) Bern.11 - 14 m. 
" 2200 110 49 330 1300 1200 1500 30 50 0.60 8 1.2 1.3 1.2 13 3 1800",  		// (52) Merg. 
" 2890 145 64 435 1300 1200 1500 40 60 0.80 10 1.3 1.7 1.4 16 3 2000",  		// (53) Bern.15 - 18 m. 
" 2400 120 53 360 1300 1200 1500 40 60 0.70 8 1.3 1.3 1.3 15 3 2000"  		// (54) Merg. 
	};
	/*
	* ------------------------------------------------------------
	* Pabaiga
	*/
/*******************************************************************************
*
* Privacios klases manipuliacijai su applet objekto elementais
*
*******************************************************************************/
    class SymItem implements ItemListener
    {

        public void itemStateChanged(ItemEvent event)
        {
            Object object = event.getSource();
            if(object == cmbbxOptimization)
                cmbbxOptimization_itemStateChanged(event);
			else
			if(object == jrbtVyras 
				|| object == jrbtMoretis 
				|| object == cmbbxAmzius 
				|| object == cmbbxAktyvumas 
				|| object == jcbPapildomosSalygos_V
				|| object == jcbPapildomosSalygos_M
				|| object == chkbxPapildoma)
				rbSuaugusieji_itemStateChanged(event);
			else
			if(object == jrbtVaikas || object == cmbbxVaikoAmzius)
				rbVaikai_itemStateChanged(event);
			
        }

        SymItem()
        {
        }
    }
    /*------------------------------------------------------------*/
    class SymAction implements ActionListener
    {

        public void actionPerformed(ActionEvent event)
        {
            Object object = event.getSource();
            if(object == btnLoad)
                btnLoad_actionPerformed(event);
            else
            if(object == btnNext2)
                btnNext2_actionPerformed(event);
            if(object == btnNext1)
                btnNext1_actionPerformed(event);
            else
            if(object == btnOK)
                btnOK_actionPerformed(event);
            else
            if(object == btnNew)
                btnNew_actionPerformed(event);
            else
            if(object == btnUpdate)
                btnUpdate_actionPerformed(event);
            else
            if(object == btnDelete)
                btnDelete_actionPerformed(event);
			else
			if (object == jbtnTekstas)
				jbtnTekstas_actionPerformed(event);
        }

        SymAction()
        {
        }
    }
    /*------------------------------------------------------------*/
    class SymMouse extends MouseAdapter
    {

        public void mouseClicked(MouseEvent event)
        {
            Object object = event.getSource();
            if(object == tblLentele)
                tblLentele_mouseClicked(event);
        }

        SymMouse()
        {
        }
    }
/*******************************************************************************
* Metodai: darbas su duomenimis
******************************************************************************/
 
 /* ------------------------------------
 *  metodas Clear isvalo duomenu laukus
 *  ------------------------------------ */
    void Clear()
    {
        txtfldName.setText("");
        txtfldPrice.setText("");
        txtfldCalories.setText("");
        txtfldProteins.setText("");
        txtfldFats.setText("");
        txtfldCarbohydrates.setText("");
        txtfldVitaminC.setText("");
        txtfldVitaminA.setText("");
        txtfldMineralCa.setText("");
        txtfldMineralNa.setText("");
        txtfldVitaB2.setText("");
        txtfldVitaB3.setText("");
        txtfldVitaB6.setText("");
        txtfldVitaB12.setText("");
        txtfldMCA.setText("");
        txtfldMNa.setText("");
        txtfldMS.setText("");
        txtfldVitaPP.setText("");
        txtfldMP.setText("");
        txtfldMJ.setText("");
        txtfldFluids.setText("");
        cmbbxTaste.setSelectedIndex(-1);
        chkbxDish.setSelected(false);
    }
 /* ------------------------------------
 *  metodas btnDelete_actionPerformed 
 *  istrina viena eilute is duomenu lenteles
 *  ------------------------------------ */
    void btnDelete_actionPerformed(ActionEvent event)
    {
        int nr = tblLentele.getSelectedRow();
        tblmdlLentele.removeRow(nr);
        Clear();
    }
 /* ------------------------------------
 *  metodas btnLoad_actionPerformed 
 *  atidaro duomenu faila ir jo duomenis 
 *  atvaizduoja ekrane
 *  ------------------------------------ */
    void btnLoad_actionPerformed(ActionEvent event) {
		D.setVisible(true);
		URL fileURL = null;
		BufferedReader dataStream = null;
		int n = 0;

		try {
			fileURL = new URL(String.valueOf(getCodeBase()) + failas);
			
			InputStream input = fileURL.openStream();
			dataStream = new BufferedReader(new InputStreamReader(input));
			lblStatus.setText("File " + fileURL.toString() + " opened");

			String s = dataStream.readLine();
			Integer sk = new Integer(s);
			n = sk.intValue();

			String strduom[] = new String[n];

			for (int i = 0; i < n; i++)
				strduom[i] = dataStream.readLine();

			tblmdlLentele.setItems(strduom);

			dataStream.close();

		} catch (MalformedURLException e) {

			e.printStackTrace();
		} catch (IOException e) {
			lblStatus.setText("Error while reading file "+failas);
			e.printStackTrace();
		}
	}

/*
 * Is failo ikrauna papildomus pageidavimus Vyrams - ivairios ligos // failo
 * strutura: //------------------------------------------------------ //<atveju
 * skaicius> //Atvejo pavadinimas // energ balt rieb angl Ca P Na J C A E B1 B2
 * B6 PP B12 1-nam kilogramui. // ir t.t.
 * //------------------------------------------------------
 */
	private void ikrautiPapildomuReikalavimuSarasa_V(String failas) {

		URL fileURL = null;
		BufferedReader dataStream = null;
		int n = 0;

		try {
			fileURL = new URL(String.valueOf(getCodeBase()) + failas);

			InputStream input = fileURL.openStream();
			dataStream = new BufferedReader(new InputStreamReader(input));

			String s = dataStream.readLine();
			Integer sk = new Integer(s);
			n = sk.intValue() + 1;
			papildomiReikalavimai_V = new String[n];
			sPavPapildomi_V = new String[n];

			sPavPapildomi_V[0] = "sveikas";
			papildomiReikalavimai_V[0] = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
			for (int i = 1; i < n; i++) {
				sPavPapildomi_V[i] = dataStream.readLine();
				papildomiReikalavimai_V[i] = dataStream.readLine();
			}

			dataStream.close();
		} catch (IOException e) {
			lblStatus.setText("Error while reading file "+failas);
			e.printStackTrace();
		}
	}
	/*
	 * Is failo papild ikrauna papildomus pageidavimus moterims nestumui,
	 * zindymus, sergant ivairiomis ligomis // failo strutura:
	 * //------------------------------------------------------ //<atveju
	 * skaicius> //Atvejo pavadinimas // energ balt rieb angl Ca P Na J C A E B1
	 * B2 B6 PP B12 1-nam kilogramui. // ir t.t.
	 * //------------------------------------------------------
	 */
	private void ikrautiPapildomuReikalavimuSarasa_M(String failas) {
		URL fileURL = null;
		BufferedReader dataStream = null;
		int n = 0;
		try {	
			fileURL = new URL(String.valueOf(getCodeBase()) + failas);
			
			InputStream input = fileURL.openStream();
			dataStream = new BufferedReader(new InputStreamReader(input));

			String s = dataStream.readLine();
			Integer sk = new Integer(s);
			n = sk.intValue() + 1;
			papildomiReikalavimai_M = new String[n];
			sPavPapildomi_M = new String[n];

			sPavPapildomi_M[0] = "sveika";
			papildomiReikalavimai_M[0] = "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
			for (int i = 1; i < n; i++) {
				sPavPapildomi_M[i] = dataStream.readLine();
				papildomiReikalavimai_M[i] = dataStream.readLine();
			}

			dataStream.close();
		} catch (IOException e) {
			lblStatus.setText("Error while reading file " + failas);
			e.printStackTrace();
		}
	}
 /*
	 * ------------------------------------ 
	 * metodas btnNew_actionPerformed iveda
	 * nauja produkta/patiekala i duomenu lentele
	 * ------------------------------------
	 */
    void btnNew_actionPerformed(ActionEvent event) {
		String temp[] = new String[1];
		try {
			String tmpPatiekalas;
			if (chkbxDish.isSelected())
				tmpPatiekalas = "1";
			else
				tmpPatiekalas = "0";
/*******************************************************************************
 * CIA(ZEMIAU) REIKIA SUSUMUOTI VISUS ELEMENTUS IS TEXBOKSU TIKSLIA TVARKA !!!
 * EILE(TVARKA) TOKIA : PRODUKAS,BALTYMAI(PROTEISNS),RIEBALAI(FATS),
 * ANGLIAVANDENIAI(CARBOHYDRAUTES),
 * KALORIJOS,A,E,C,B1,B2,B3,B6,B12,PP,CA,NA,S,FTOR(P),J(JODAS),VAIZDAS,
 * PATIEKALAS,KAINA. Patiekas pridedamas taip : ... + "," + tmpPatiekalas +
 * ","+... *Marijus: BUVO pamirsta prideti patiekalo pozymi :))
 ******************************************************************************/
        temp[0] = txtfldName.getText() + "," +
        txtfldProteins.getText() + "," + 
        txtfldFats.getText() + "," + 
        txtfldCarbohydrates.getText() + "," + 
        txtfldCalories.getText() + "," +         
        txtfldVitaminC.getText() + "," +
        txtfldVitaminA.getText() + "," +
        txtfldMineralCa.getText() + "," +
        txtfldMineralNa.getText() + "," +
        txtfldVitaB2.getText() + "," +
        txtfldVitaB3.getText() + "," +
        txtfldVitaB6.getText() + "," +
        txtfldVitaB12.getText() + "," +
        txtfldVitaPP.getText() + "," +
        txtfldMCA.getText() + "," +
        txtfldMNa.getText() + "," +
        txtfldMS.getText() + "," +
        txtfldMP.getText() + "," +
        txtfldMJ.getText() + "," +
        cmbbxTaste.getSelectedItem().toString() + "," + 
        tmpPatiekalas.toString() + "," + 
        txtfldPrice.getText();

			if (tblLentele.getRowCount() == 1)
				tblmdlLentele.setItems(temp);
			else
				tblmdlLentele.addRow(temp[0]);
			Clear();
		} catch (NullPointerException _ex) {
			lblStatus.setText("Please enter all product fields!!!");
		}
    }
 /*
	 * ------------------------------------ 
	 * metodas btnNext1_actionPerformed
	 * Atlieka veiksma "Toliau" 1. is duomenu ivedimo lango eina i optimizavimo
	 * parametru nustatymo langa 
	 * ------------------------------------
	 */
    void btnNext1_actionPerformed(ActionEvent event)
    {
        formProduct(tblmdlLentele);
        if(productCount == 0)
            lblStatus.setText("No data");
        else
        if(!duomenuKlaida)
        {
            lblStatus.setText("");
            pnlPageidavimai.setEnabled(true);
            tbdpnlBendras.setSelectedIndex(1);
        } else
        {
         lblStatus.setText("Wrong data.");
        }
    }
 /* ----------------------------------------------------
 *  Metodas SetProdOnTaste() suformuoja sarasa produktu
 *  kuriu skonis yra didesnis arba 2 dydziais mazesnis
 *  negu pasirinktas skaiciavimams
 *  ----------------------------------------------------*/
    private void SetProdOnTaste() {
		// productCount >0 (pries kreipiantis buvo patikrinta
		// atrenka produktus pagal skonio faktorius
		int j = 0;
		int sv = cmbbxIAddTaste.getSelectedIndex();
		float sko = 0;

		activProdCnt = 0;
		for (int i = 0; i < productCount; i++) {
			sko = produktai[i].getTaste(); // gauk skoni
			// ivedam tik tuos jei skonis mus tenkina,
			if (sko >= sv) {
				j++;
				produktai1[j - 1] = produktai[i];
			}
		}

		if (j != 0) {
			activProdCnt = j; // produktu skaicius kurie itraukiami i
								// skaiciavimus
			prodActiv = new Product[activProdCnt+1];
			for (int i = 1; i <= activProdCnt; i++) {
				prodActiv[i] = produktai1[i-1];
			}
		}

	}

 /*
	 * ------------------------------------ 
	 * metodas btnNext_actionPerformed
	 * Atlieka veiksma "Toliau" 2. is nustatymo langu kreipiasi i optimizacija
	 * ir atlieka veiksmus bei gauna rezultatus
	 * ------------------------------------
	 */
   
    
    private void btnNext2_actionPerformed(ActionEvent event) {
		int opt_func_salyga;
		if (productCount == 0) {
			lblStatus.setText("No data");
			tbdpnlBendras.setSelectedIndex(0);
		} else {
			
								
			produktai1 = new Product[productCount];
			SetProdOnTaste();
			opt_func_salyga = 0;
			if (activProdCnt == 0) {
				tbdpnlBendras.setSelectedIndex(0);
			} else {
				
				int tmpDienos=0;
				if (chkbxDay.isSelected()){
					tmpDienos = 7;}
					else{
					tmpDienos = 1;}
				
				double weight =Converter.stringToDouble(txtfldWeight.getText());
				double weight2;
				// skirtas tam, kad esant pasirinktam vaikui, koeficientas prie elementu, kurie nustato pagal svori, butu vienas.
				// duomenyse pageidavimai vaikui nenurodyti pagal svori, todel visiems vienodi
				if (jrbtVaikas.isSelected())
					weight2 = 1;
				else
					weight2 = weight;
				// ----------------------------------
				solve lpSolve = new solve();
				lprec lpRec = new lprec(0, activProdCnt);
				// debug = 1/0 - ijungti/isjungti debug rezima
				lpRec.debug = Constants.Debug;

				// suformuojam sarasa

				for (int i = 1; i <= activProdCnt; i++)
					if (prodActiv[i].getDish() == 1) // jei patiekalas
					{
						lpSolve.set_int(lpRec, i, (short) 1);
						lpSolve.set_upbo(lpRec, i, Constants.maxPatiekaluKiekis); // kiek patiekalu (virsutine riba)
					} else { // jei ne patiekalas
						lpSolve.set_int(lpRec, i, (short) 0);
						// SAULIUS 2010-03-28 užkomentavau šituos ribojimus, nes jie dirbtiniai, o turi būti tik sanitarinės normos
						//lpSolve.set_lowbo(lpRec,i, 0.03);						
						//lpSolve.set_upbo(lpRec, i, Constants.maxGramuKiekis*tmpDienos); // kiek gramu (virsutine riba)
					}
				// apribojimu suformavimas
				// BALTYMAI,RIEBALAI, ANGLIAVANDENIAI,KALORIJOS,A,E,C,B1,B2,B3,B6,B12,
				// PP,CA,NA,S,FTOR(P),J(JODAS),VAIZDAS,KAINA.
				double data[] = new double[activProdCnt + 1];
				double Cal = Converter.stringToDouble(ReikiaKal.getText());
				double Fat = Converter.stringToDouble(ReikiaRieb.getText());
				double Pro = Converter.stringToDouble(ReikiaBalt.getText());
				double Car = Converter.stringToDouble(ReikiaAngl.getText());
				double VitA = Converter.stringToDouble(ReikiaVitA.getText());
				double VitB1 = Converter.stringToDouble(ReikiaVitB1.getText());
				double VitB2 = Converter.stringToDouble(ReikiaVitB2.getText());
				double VitB3 = Converter.stringToDouble(ReikiaVitB3.getText());
				double VitB6 = Converter.stringToDouble(ReikiaVitB6.getText());
				double VitB12 = Converter.stringToDouble(ReikiaVitB12.getText());
				double VitC = Converter.stringToDouble(ReikiaVitC.getText());
				double VitE = Converter.stringToDouble(ReikiaVitE.getText());
				double VitPP = Converter.stringToDouble(ReikiaVitPP.getText());
				double MinCa = Converter.stringToDouble(ReikiaKalc.getText());
				double MinNa = Converter.stringToDouble(ReikiaNatr.getText());
				double Fosf = Converter.stringToDouble(ReikiaFosf.getText());
				double Siera = Converter.stringToDouble(ReikiaSer.getText());
				double J = Converter.stringToDouble(ReikiaJ.getText());
				double UpVitA = Converter.stringToDouble(ReikiaVitA.getText());
				double UpVitB1 = Converter.stringToDouble(ReikiaVitB1.getText());
				double UpVitB2 = Converter.stringToDouble(ReikiaVitB2.getText());
				double UpVitB3 = Converter.stringToDouble(ReikiaVitB3.getText());
				double UpVitB6 = Converter.stringToDouble(ReikiaVitB6.getText());
				double UpVitB12 = Converter.stringToDouble(ReikiaVitB12.getText());
				double UpVitC = Converter.stringToDouble(ReikiaVitC.getText());
				double UpVitE = Converter.stringToDouble(ReikiaVitE.getText());
				double UpVitPP = Converter.stringToDouble(ReikiaVitPP.getText());
				double UpMinCa = Converter.stringToDouble(ReikiaKalc.getText());
				double UpMinNa = Converter.stringToDouble(ReikiaNatr.getText());
				double UpFosf = Converter.stringToDouble(ReikiaFosf.getText());
				double UpSiera = Converter.stringToDouble(ReikiaSer.getText());
				double BeautyFactor = Converter.stringToDouble(cmbbxImportance.getText());
				double UpLiquid = Converter.stringToDouble(ReikiaLiquid.getText());
				double Liquid = Converter.stringToDouble(ReikiaLiquid.getText());
				fMaistoIvairumas = Converter.stringToDouble(jIvairove.getText());

				// beautyfactor inervalas nuo (0 iki+begalybes)
				// (0;1) - suvartojama maziau negu reikia - tuo atzvilgiu dieta neoptimali todel grozio faktorius nuo 1
				// (1) -tiek kiek reikia
				// (1;+begalybe) - daugiau nei reikia

				double Paklaida = Converter.stringToDouble(jPaklaida.getText());
				double rhs;

				// Optimizuojama pagal kaina, ribojimus nusako kalorijos (ju skaiciu galima keisti pagal "grozio" faktoriu), baltymai,riebalai ir kt.
				// skonio faktorius veikia kaina 10%, juo didesnis skonis tuo daugiau norima uz preke moketi, t.y. kaina mazeja didejant skoniui
				// Tikslo funkcija: minx->sum((ci-si)+g*ai1-d*di)xi-g*b1.
				// g*b1 galima praleisti, nes jis vienodas visiems patiekalams
				// ci - produkto kg/vnt kaina,
				// si - skonio "kaina",
				// g - grozio faktorius,
				// di - maisto ivairoves (diversity) faktorius:
				// di = 1 - jei i-tasisi produktas yra patiekalas, kitu atveju di = 0
				// b1 - kaloriju norma

				double mytest = 0;
				double correction = 0;
				for (int i = 1; i <= activProdCnt; i++) { // 90(84) formule vienam produktui

					/* SAULIUS 2010-03-28 senesnė formulė
					  		data[i] = ((prodActiv[i].price - prodActiv[i].price * prodActiv[i].Taste * Constants.tasteIndex) + 
							BeautyFactor * tmpDienos *prodActiv[i].calories - fMaistoIvairumas.doubleValue()
							* prodActiv[i].getDish());
					*/					
					
					// SAULIUS 2010-03-28 "correction" suvienodina matavimo vienetus produktams, kad būtų Lt/100g ir kcal/100g
					if (prodActiv[i].getDish() == 1)
						correction = 1; 
					else 
						correction = 0.1;
						
					data[i] = ((prodActiv[i].price - prodActiv[i].price * prodActiv[i].Taste * Constants.tasteIndex) 
							+ correction * BeautyFactor * prodActiv[i].calories
							- fMaistoIvairumas.doubleValue()* prodActiv[i].getDish());						
						
					mytest = mytest + (prodActiv[i].price - prodActiv[i].price * prodActiv[i].Taste * Constants.tasteIndex);
					
					if (data[i] < -10000) { // labai mazas skaicius, rezultate gausime nesamone
						opt_func_salyga = 1; // skaiciavimu neatliksime
					}
				}
				if (opt_func_salyga == 1) {
					lblStatus.setForeground(new java.awt.Color(204, 102, 0));
					lblStatus.setText("Dieta neskaiciuojama - mirsit nuo persivalgymo");
				} else {
					lpSolve.set_obj_fn(lpRec, data);
					lpSolve.set_minim(lpRec);
		
					/* Calories */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getCalories();
					//apatine riba
					rhs = (Cal - Cal * Paklaida) * tmpDienos *weight2 * Constants.lowerTolCalories;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//virsutine riba
					rhs = (Cal + Cal * Paklaida) * tmpDienos *weight2 * Constants.upperTolCalories;
					lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* Proteins */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getProteins();
					rhs = (Pro - Pro * Paklaida) * tmpDienos *weight2 * Constants.lowerTolProteins;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					rhs = (Pro + Pro * Paklaida) * tmpDienos *weight2 * Constants.upperTolProteins;
					lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* Fats */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getFats();
					rhs = (Fat - Fat * Paklaida) * tmpDienos *weight2 * Constants.lowerTolFats;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					rhs = (Fat + Fat * Paklaida) * tmpDienos *weight2 * Constants.upperTolFats;
					lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* Carbohydrates */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getCarbohydrates();
					//rhs = (tmpDienos *Car - Car * Paklaida) * weight2 * Constants.lowerTolCarbohydrates;
					rhs = (Car - Car * Paklaida) * tmpDienos * weight2 * Constants.lowerTolCarbohydrates;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					rhs = (Car + Car * Paklaida) * tmpDienos *weight2 * Constants.upperTolCarbohydrates;
					lpSolve.add_constraint(lpRec, data, LE, rhs);
					
            		/* mikroelementai ir vitaminai pateikiami fiksuota dienos norma zmogui */

					/* vit A */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getVitA();
					rhs = (VitA - VitA * Paklaida) * tmpDienos* Constants.lowerTolVitA;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitA + VitA * Paklaida) * Constants.upperTolVitA;

					/* vit B1 */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitB1;
					rhs = (VitB1 - VitB1 * Paklaida) * tmpDienos* Constants.lowerTolVitB1;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitB1 + VitB1 * Paklaida) * Constants.upperTolVitB1;
					//lpSolve.add_constraint_up(lpRec, data, LE, rhs);
					
					/* vit B2 */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitB2;
					rhs = (VitB2 - VitB2 * Paklaida) * tmpDienos* Constants.lowerTolVitB2;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitB2 + VitB2 * Paklaida) * Constants.upperTolVitB2;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* vit B3 */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitB3;
					rhs = (VitB3 - VitB3 * Paklaida) * tmpDienos* Constants.lowerTolVitB3;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitB3 + VitB3 * Paklaida) * Constants.upperTolVitB3;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* vit B6 */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitB6;
					rhs = (VitB6 - VitB6 * Paklaida) * tmpDienos* Constants.lowerTolVitB6;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitB6 + VitB6 * Paklaida) * Constants.upperTolVitB6;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* vit B12 */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitB12;
					rhs = (VitB12 - VitB12 * Paklaida) * tmpDienos* Constants.lowerTolVitB12;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitB12 + VitB12 * Paklaida) * Constants.upperTolVitB12;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* vit C */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getVitC();
					rhs = (VitC - VitC * Paklaida) * tmpDienos* Constants.lowerTolVitC;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitC + VitC * Paklaida) * Constants.upperTolVitC; 
					//lpSolve.add_constraint(lpRec, data, LE, rhs);

					/* vit E */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitE;
					rhs = (VitE - VitE * Paklaida) * tmpDienos* Constants.lowerTolVitE;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitE + VitE * Paklaida) * Constants.upperTolVitE;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);

					/* vit PP */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].vitPP;
					rhs = (VitPP - VitPP * Paklaida) * tmpDienos* Constants.lowerTolVitPP;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (VitPP + VitPP * Paklaida) * Constants.upperTolVitPP;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);

					/* mikrel Ca */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getMinCa();
					rhs = (MinCa - MinCa * Paklaida) * tmpDienos* Constants.lowerTolMikrelCa;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (MinCa + MinCa * Paklaida) * Constants.upperTolMikrelCa;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);

					/* mikrel Na */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getMinNa();
					rhs = (MinNa - MinNa * Paklaida) * tmpDienos* Constants.lowerTolMikrelNa;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (MinNa + MinNa * Paklaida) * Constants.upperTolMikrelNa;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);

					/* mikrel S */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].minS;
					rhs = (Siera - Siera * Paklaida) * tmpDienos* Constants.lowerTolMikrelS;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (Siera + Siera * Paklaida) * Constants.upperTolMikrelS;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);

					/* mikrel P */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].minP;
					rhs = (Fosf - Fosf * Paklaida) * tmpDienos* Constants.lowerTolMikrelP;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					//rhs = (Fosf + Fosf * Paklaida) * Constants.upperTolMikrelP;
					//lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					/* Liquids */
					for (int i = 1; i <= activProdCnt; i++)
						data[i] = prodActiv[i].getLiquid();
					rhs = (Liquid - Liquid * Paklaida) *tmpDienos* Constants.lowerTolFluid;
					lpSolve.add_constraint(lpRec, data, GE, rhs);
					rhs = (Liquid + Liquid * Paklaida) *tmpDienos* Constants.upperTolLiquid;
					lpSolve.add_constraint(lpRec, data, LE, rhs);
					
					UpVitC = tmpDienos *VitC * Constants.upperTolVitC;
					UpVitA = tmpDienos *VitA * Constants.upperTolVitA;
					UpMinCa = tmpDienos *MinCa * Constants.upperTolMikrelCa;
					UpMinNa = tmpDienos *MinNa * Constants.upperTolMikrelNa;
					UpVitE = tmpDienos *VitE * Constants.upperTolVitE;
					UpVitB1 = tmpDienos *VitB1 * Constants.upperTolVitB1;
					UpVitB2 = tmpDienos *VitB2 * Constants.upperTolVitB2;
					UpVitB3 = tmpDienos *VitB3 * Constants.upperTolVitB3;
					UpVitB6 = tmpDienos *VitB6 * Constants.upperTolVitB6;
					UpVitB12 = tmpDienos *VitB12 * Constants.upperTolVitB12;
					UpVitPP = tmpDienos *VitPP * Constants.upperTolVitPP;
					UpFosf = tmpDienos *Fosf * Constants.upperTolMikrelP;
					UpSiera = tmpDienos *Siera * Constants.upperTolMikrelS;
					UpLiquid = tmpDienos *Liquid * Constants.upperTolLiquid;
					
					PrintStream ps;
					FileOutputStream out; 
					try {
						out = new FileOutputStream("myfile.txt");
	                    ps = new PrintStream(out);	
	                    lpSolve.write_LP(lpRec, ps);
					}
	                catch (Exception e){
	                        System.err.println ("Error in writing to file");
	                }                
					
					int rez = lpSolve.solve(lpRec);

					if (rez == 0) {
						lblStatus.setText("Optimali dieta rasta, skliaustuose prie vitaminu ir mikroelementu nurodyta didziausia rekomenduojama doze");
						double nn = 0;
						int sk = 0;
						for (int i = 1; i <= lpSolve.get_lpcolumns(lpRec); i++)
							if (lpSolve.get_lpsolution(lpRec, lpSolve.get_lprows(lpRec) + i) != nn)
								sk++;
						String rezai[] = new String[sk];
						double sumcal = 0.0D;
						double sumpro = 0.0D;
						double sumfat = 0.0D;
						double sumcar = 0.0D;
						int nr = 0;
						double sumak = 0.0D;
						double sumaks = 0.0D;
						double mase = 0;
						int ivairove = 0;
						
						VitC = VitA = MinCa = MinNa = VitE = VitB1 = VitB2 = VitB3 = VitB6 = VitB12 = VitPP = Fosf = Siera = J = Liquid = 0.0;
						for (int i = 1; i <= lpSolve.get_lpcolumns(lpRec); i++){
							int rows = lpSolve.get_lprows(lpRec);
							if (lpSolve.get_lpsolution(lpRec, rows + i) != nn) {
								if (prodActiv[i].getDish() == 1)
									rezai[nr] = prodActiv[i].getName() + "," + Integer.toString((int)lpSolve.get_lpsolution(lpRec, rows + i)) + " vnt";
								else
									rezai[nr] = prodActiv[i].getName() + "," + Double.toString(lpSolve.get_lpsolution(lpRec, rows + i)*10) + " 100g";
								sumcal += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getCalories();
								sumpro += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getProteins();
								sumfat += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getFats();
								sumcar += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getCarbohydrates();
								sumak += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getPrice();
								sumaks += lpSolve.get_lpsolution(lpRec, rows + i) * ((double) prodActiv[i].getPrice() - (double) prodActiv[i].getPrice() * (double) prodActiv[i].getTaste() * Constants.tasteIndex);
								VitC += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitC();
								VitA += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitA();
								MinCa += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getMinCa();
								MinNa += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getMinNa();
								VitE += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitE();
								VitB1 += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitB1();
								VitB2 += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitB2();
								VitB3 += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitB3();
								VitB6 += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitB6();
								VitB12 += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitB12();
								VitPP += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getVitPP();
								Fosf += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getMinP();
								Siera += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getMinS();
								J += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getMinJ();
								Liquid += lpSolve.get_lpsolution(lpRec, rows + i) * (double) prodActiv[i].getLiquid();
								ivairove += lpSolve.get_lpsolution(lpRec, rows + i) * prodActiv[i].getDish();
								nr++;
								mase += lpSolve.get_lpsolution(lpRec, rows + i);
								
								
							}
						}
						tblmdlRezultatai.setItems(rezai);

						DecimalFormat nf = new DecimalFormat(Constants.doublePattern);

						lblCaloriesTotal.setText(" ");
						lblProteinsTotal.setText(" ");
						lblFatsTotal.setText(" ");
						lblCarbohydratesTotal.setText(" ");
						lblPriceTotal.setText(" ");
						lblPriceTotalS.setText(" ");
						lblVitATotal.setText(" ");
						lblVitB1Total.setText(" ");
						lblVitB2Total.setText(" ");
						lblVitB3Total.setText(" ");
						lblVitB6Total.setText(" ");
						lblVitB12Total.setText(" ");
						lblVitCTotal.setText(" ");
						lblVitETotal.setText(" ");
						lblVitPPTotal.setText(" ");
						lblMinCaTotal.setText(" ");
						lblMinNaTotal.setText(" ");
						lblMinSTotal.setText(" ");
						lblMinPTotal.setText(" ");
						lblMinJTotal.setText(" ");
						lblMinLiquidTotal.setText(" ");
						jLabelIvairovesSprendimas2.setText(" ");
						
						lblCaloriesTotal.setText(nf.format(sumcal));
						lblProteinsTotal.setText(nf.format(sumpro));
						lblFatsTotal.setText(nf.format(sumfat));
						lblCarbohydratesTotal.setText(nf.format(sumcar));
						lblPriceTotal.setText(nf.format(sumak));
						lblPriceTotalS.setText(nf.format(sumaks));
						lblVitATotal.setText(nf.format(VitA)+ " ("+ nf.format(UpVitA) +")");
						lblVitB1Total.setText(nf.format(VitB1) + " ("+ nf.format(UpVitB1) +")");
						lblVitB2Total.setText(nf.format(VitB2)+ " ("+ nf.format(UpVitB2) +")");
						lblVitB3Total.setText(nf.format(VitB3)+ " ("+ nf.format(UpVitB3) +")");
						lblVitB6Total.setText(nf.format(VitB6)+ " ("+ nf.format(UpVitB6) +")");
						lblVitB12Total.setText(nf.format(VitB12)+ " ("+ nf.format(UpVitB12) +")");
						lblVitCTotal.setText(nf.format(VitC)+ " ("+ nf.format(UpVitC) +")");
						lblVitETotal.setText(nf.format(VitE)+ " ("+ nf.format(UpVitE) +")");
						lblVitPPTotal.setText(nf.format(VitPP)+ " ("+ nf.format(UpVitPP) +")");
						lblMinCaTotal.setText(nf.format(MinCa)+ " ("+ nf.format(UpMinCa) +")");
						lblMinNaTotal.setText(nf.format(MinNa)+ " ("+ nf.format(UpMinNa) +")");
						lblMinSTotal.setText(nf.format(Siera)+ " ("+ nf.format(UpSiera) +")");
						lblMinPTotal.setText(nf.format(Fosf)+ " ("+ nf.format(UpFosf) +")");
						lblMinJTotal.setText(nf.format(J)+ " (nezinoma)");
						lblMinLiquidTotal.setText(nf.format(Liquid)+ " ("+ nf.format(UpLiquid) +")");
						jLabelIvairovesSprendimas2.setText(String.valueOf(ivairove));
					} else {
						String tuscias[] = new String[0];
						tblmdlRezultatai.setItems(tuscias);
						lblCaloriesTotal.setText("");
						lblProteinsTotal.setText("");
						lblFatsTotal.setText("");
						lblCarbohydratesTotal.setText("");
						lblPriceTotal.setText("");
						lblPriceTotalS.setText("");
						lblVitATotal.setText("");
						lblVitB1Total.setText("");
						lblVitB2Total.setText("");
						lblVitCTotal.setText("");
						lblVitB3Total.setText("");
						lblVitETotal.setText("");
						lblVitB6Total.setText("");
						lblVitPPTotal.setText("");
						lblVitB12Total.setText("");
						lblMinCaTotal.setText("");
						lblMinNaTotal.setText("");
						lblMinSTotal.setText("");
						lblMinPTotal.setText("");
						lblMinJTotal.setText("");
						lblMinLiquidTotal.setText("");
						jLabelIvairovesSprendimas2.setText("0");
						lblStatus.setText("Neimanoma patenkinti sanitariniu normu !");
					}
					pnlRezultatai.setEnabled(true);
					tbdpnlBendras.setSelectedIndex(2);
				}
			}
		}
	}
 /*
	 * ------------------------------------ metodas btnOK_actionPerformed Priskiria duomenu failo nuoroda(handle) ------------------------------------
	 */
    void btnOK_actionPerformed(ActionEvent event)
    {
        failas = txtfldFailas.getText();
        D.dispose();
    }
 /*
	 * ------------------------------------ metodas btnUpdate_actionPerformed Atnaujina egzistuojanti patiekala Istrina is lenteles ir iraso i gala su pakeistais duomenimis
	 * ------------------------------------
	 */
    void btnUpdate_actionPerformed(ActionEvent event)   
    {
       String tmpPatiekalas;
        if(chkbxDish.isSelected())
            tmpPatiekalas = "1";
        else
            tmpPatiekalas="0";
        int nr = tblLentele.getSelectedRow();
        tblmdlLentele.removeRow(nr);
/*******************************************************************************************************************************************************************************************************
 * CIA(ZEMIAU) REIKIA SUSUMUOTI VISUS ELEMENTUS IS TEXBOKSU TIKSLIA TVARKA !!! EILE(TVARKA) TOKIA : PRODUKAS,BALTYMAI(PROTEISNS),RIEBALAI(FATS), ANGLIAVANDENIAI(CARBOHYDRAUTES),
 * KALORIJOS,A,E,C,B1,B2,B3,B6,B12,PP,CA,NA,S,FTOR(P), J(JODAS),VAIZDAS, PATIEKALAS,KAINA. Patiekas pridedamas taip : ... + "," + tmpPatiekalas + ","+...
 ******************************************************************************************************************************************************************************************************/
        String temp = txtfldName.getText() + "," + 
        txtfldProteins.getText() + "," + 
        txtfldFats.getText() + "," + 
        txtfldCarbohydrates.getText() + "," + 
        txtfldCalories.getText() + "," +         
        txtfldVitaminC.getText() + "," +
        txtfldVitaminA.getText() + "," +
        txtfldMineralCa.getText() + "," +
        txtfldMineralNa.getText() + "," +
        txtfldVitaB2.getText() + "," +
        txtfldVitaB3.getText() + "," +
        txtfldVitaB6.getText() + "," +
        txtfldVitaB12.getText() + "," +
        txtfldVitaPP.getText() + "," +
        txtfldMCA.getText() + "," +
        txtfldMNa.getText() + "," +
        txtfldMS.getText() + "," +
        txtfldMP.getText() + "," +
        txtfldMJ.getText() + "," +
        cmbbxTaste.getSelectedItem().toString() + "," +  
        tmpPatiekalas.toString() + "," +               
        txtfldPrice.getText() + "," +
        txtfldFluids.getText();        
        tblmdlLentele.addRow(temp);
        Clear();
    }
 /*
 * metodas pageidavimui ikrovimui ir tekstinio lauko
 * lauke duomenys turi buti tokia tvarka:
 *1  	Energija (kcal), 
  2 	Baltymai (g), 
  3	Riebalai (g), 
  4	Angliavandeniai (g), 
  5	Ca (mg), 
  6	P (mg), 
  	Mg (mg),  <<-- Sitas nenaudojamas
   	Fe (mg), <<-- Sitas nenaudojamas
   	Zn (mg),  <<-- Sitas nenaudojamas
  7	Na (mg), 
   	K (mg), <<-- Sitas nenaudojamas
  8	J (mg), 
  9	C (mg),
 10	A (mkg ret. ekv.), 
 11	E (mg, tok. ekv.),
   	D (mkg), <<-- Sitas nenaudojamas
 12	B1 (mg), 
 13	B2 (mg), 
          B3 <<-- sito truksta duomenyse
 14	B6 (mg), 
 15	PP(mg niac. ekv.), 
   	Folio r. (mkg),  <<-- sitas nenaudojamas
 16	B12 (mkg)
          S <<-- Sito truksta duomenyse
 17 Skysciai (ml)          
 */
 void jbtnTekstas_actionPerformed(ActionEvent event)
 {
	StringTokenizer strtkPageidavimai, strtkPapildomi;
	strtkPageidavimai = new StringTokenizer(jReikalavimuTekstas.getText().trim(), " ");
	Double suma;
	
	int elCount = 17;
	
	if (strtkPageidavimai.countTokens() != elCount)
	{
		JOptionPane.showMessageDialog(this, "Turi būti 17 elementai!");
	}
	else
	{
		dienosReikalavimai = new String [elCount];
		
		if( chkbxPapildoma.isSelected() )
		{	// jei yra papildomu pageidavimu
			
			strtkPapildomi = new StringTokenizer(tfldPapildomi.getText().trim() ," ");
			
			for(int i=0; i<elCount; i++)
			{
				suma = Double.valueOf(strtkPageidavimai.nextToken());//.doubleValue() + Double.valueOf(strtkPapildomi.nextToken()).doubleValue();
				if (suma.doubleValue() < 0)
					suma = Double.valueOf(0);
	
					suma = new Double(Math.round(suma.doubleValue()*100.0)/100.0);
				dienosReikalavimai[i] = suma.toString();
				
			}
		}
		else
		{	// jei nera papildomu pageidavimu
			
			for(int i=0; i<elCount; i++)
			{
				
				dienosReikalavimai[i] = strtkPageidavimai.nextToken();
			}
		}
		atnaujintiPageidavimus();
	}
	
 }
/* metodas is masyvo String dienosReikalavimai[22]  
*  suveda i tektsinius laukus pageidavimus
*/ 
void atnaujintiPageidavimus()
{
	//================================
	ReikiaKal.setText(dienosReikalavimai[0]);
	ReikiaBalt.setText(dienosReikalavimai[1]);
	ReikiaRieb.setText(dienosReikalavimai[2]);
	ReikiaAngl.setText(dienosReikalavimai[3]);
	//================================
	ReikiaKalc.setText(dienosReikalavimai[4]);
	ReikiaFosf.setText(dienosReikalavimai[5]);
	ReikiaNatr.setText(dienosReikalavimai[6]);
	ReikiaJ.setText(dienosReikalavimai[7]);
	//================================
	ReikiaVitC.setText(dienosReikalavimai[8]);
	ReikiaVitA.setText(dienosReikalavimai[9]);
	ReikiaVitE.setText(dienosReikalavimai[10]);
	ReikiaVitB1.setText(dienosReikalavimai[11]);
	ReikiaVitB2.setText(dienosReikalavimai[12]);
	ReikiaVitB6.setText(dienosReikalavimai[13]);
	ReikiaVitPP.setText(dienosReikalavimai[14]);
	ReikiaVitB12.setText(dienosReikalavimai[15]);
	//=================================
	ReikiaLiquid.setText(dienosReikalavimai[16]);
	
	//ReikiaVitB3.setText("1.8");
	//ReikiaSer.setText("1000");
} 
 /* ------------------------------------
 *  metodas cmbbxOptimization_itemStateChanged 
 *  Neaiskus metodas. Tikriausiai buvo 
 *  anksciau naudojamas identifikuoti 
 *  pasikeitusiems duomenims bet dabar
 *  neturi prasmes(?)
 *  ------------------------------------ */
    void cmbbxOptimization_itemStateChanged(ItemEvent itemevent)
    {
    }
/*
Metodas ikrauna pageidavimu eilute pagal suaugosiusiu poreikius
ijungia svorio lauka
*/
	void rbSuaugusieji_itemStateChanged(ItemEvent itemevent)
    {
		txtfldWeight.setEnabled(true);
		cmbbxAktyvumas.setEnabled(true);
		cmbbxAmzius.setEnabled(true);
		cmbbxVaikoAmzius.setEnabled(false);
		int kuris = kuriDuomenuEilute();
		jReikalavimuTekstas.setText(pageidavimaiStandartiniai[kuris]);
		if (jrbtVyras.isSelected())
		{
			jcbPapildomosSalygos_V.setEnabled(true);
			jcbPapildomosSalygos_M.setEnabled(false);
			pasirinktasPapildomas();
		}
		else
		{
			jcbPapildomosSalygos_M.setEnabled(true);
			jcbPapildomosSalygos_V.setEnabled(false);
			pasirinktasPapildomas();
		}
    }
	/*
Metodas ikrauna pageidavimu eilute pagal vaiku poreikius
isjungia svorio lauka

*/
	void rbVaikai_itemStateChanged(ItemEvent itemevent)
    {
		txtfldWeight.setEnabled(false);
		cmbbxAktyvumas.setEnabled(false);
		cmbbxAmzius.setEnabled(false);
		cmbbxVaikoAmzius.setEnabled(true);
		int kuris = kuriDuomenuEilute();
		jReikalavimuTekstas.setText(pageidavimaiStandartiniai[kuris]);
		
		jcbPapildomosSalygos_M.setEnabled(false);
		jcbPapildomosSalygos_V.setEnabled(false);
    }
	
	void pasirinktasPapildomas()
	{
		if (chkbxPapildoma.isSelected())
		{
			if(jrbtVyras.isSelected())
			{
				tfldPapildomi.setText(papildomiReikalavimai_V[jcbPapildomosSalygos_V.getSelectedIndex()]);
			}
			else
			{
				tfldPapildomi.setText(papildomiReikalavimai_M[jcbPapildomosSalygos_M.getSelectedIndex()]);
			}
		}
		else
			tfldPapildomi.setText("");
	}
	
/*
* Metodas nustato amžiaus, lyties ir aktyvumo pasirinkimus, kurią duomenų eilutę 
įkrauti į programą.
*/
	int kuriDuomenuEilute()
	{
		int amzius, svoris, aktyvumas, lytis=0, svorioRiba=80;
		boolean vaikas, vyras, moteris;
		double weight = Double.valueOf(txtfldWeight.getText()).doubleValue();
		// nuistato kuris radio mygtukas pazymetas
		if (jrbtVaikas.isSelected())
		{
			vaikas = true;
			vyras = false;
			moteris = false;
		}
		else
		{
			vaikas = false;
			if (jrbtVyras.isSelected())
			{
				vyras = true;
				moteris = false;
				lytis = 0;
				svorioRiba = 80;
			}
			else
			{
				vyras = false;
				moteris = true;
				lytis = 1;
				svorioRiba = 65;
			}
		}
		
		//jei vaikas
		if (vaikas == true)
		{
			amzius = cmbbxVaikoAmzius.getSelectedIndex();
			return 48 + amzius;
		}
		else
		{
			amzius = cmbbxAmzius.getSelectedIndex();
			if (weight < svorioRiba)
			 	svoris = 0;
			else
				svoris = 1;
			aktyvumas = cmbbxAktyvumas.getSelectedIndex();
			return aktyvumas*12 + lytis*6 + amzius*2 + svoris;
		}
			
	}
 /* ------------------------------------
 *  metodas formProduct 
 *  Suformuoja produkto objekta su visais
 *  jam priklausanciais duomenimis
 *  Perskaiciuoja duomenis vienam produkto
 *  kilogramui jei tai ne patiekalas
 *  ------------------------------------ */
    void formProduct(StringTableModel model)
    {
        duomenuKlaida = false;
        String temp = "";
        productCount = model.getRowCount();
        produktai = new Product[productCount];
        int j;float dg;
        for(int i = 0; i < productCount; i++)
        {
/******************************************************************************
 * EILE(TVARKA) TOKIA : 
 * PRODUKAS,BALTYMAI,RIEBALAI, ANGLIAVANDENIAI,KALORIJOS,A,E,C,B1,B2,B3,B6,B12,
 * PP,CA,NA,S,FTOR(P), J(JODAS),VAIZDAS,PATIEKALAS,KAINA.
 *****************************************************************************/          
            produktai[i] = new Product();
            produktai[i].setName(model.getElementAt(i, 0).toString());
            j=i+1;
            try
            {
                temp = model.getElementAt(i, 20).toString();
                Integer vv = Integer.valueOf(temp);
                if(vv.intValue() == 0 || vv.intValue() == 1)
                {
                    produktai[i].setDish(vv.intValue());
                    
                }
                else
                {
                    duomenuKlaida = true;
                    break;
                }
                if (produktai[i].getDish()==0){
                    dg=10;                 
                }else {
                    dg=1;                   
                }

        /*suvedame produktus perskaiciuodami ju dedamasias kilograme JEI TAI NE PATIEKALAS*/
                temp = model.getElementAt(i, 1).toString();
                Float v = Float.valueOf(temp);
                produktai[i].proteins=dg*v.floatValue();
                
                temp = model.getElementAt(i, 2).toString();
                v = Float.valueOf(temp);
                produktai[i].fats=dg*v.floatValue(); 
                
                temp = model.getElementAt(i, 3).toString();
                v = Float.valueOf(temp);
                produktai[i].carbohydrates=dg*v.floatValue();
                 
                temp = model.getElementAt(i, 4).toString();
                v = Float.valueOf(temp);
                produktai[i].calories=dg*v.floatValue();
                
                temp = model.getElementAt(i, 5).toString();
                v = Float.valueOf(temp);
                produktai[i].vitA=dg*v.floatValue();
                
                temp = model.getElementAt(i, 6).toString();
                v = Float.valueOf(temp);
                produktai[i].vitE=dg*v.floatValue();
                
                temp = model.getElementAt(i, 7).toString();
                v = Float.valueOf(temp);
                produktai[i].vitC=dg*v.floatValue();
                
                temp = model.getElementAt(i, 8).toString();
                v = Float.valueOf(temp);
                produktai[i].vitB1=dg*v.floatValue();
      
                temp = model.getElementAt(i, 9).toString();
                v = Float.valueOf(temp);
                produktai[i].vitB2=dg*v.floatValue();
                
                temp = model.getElementAt(i, 10).toString();
                 v = Float.valueOf(temp);
                produktai[i].vitB3=dg*v.floatValue();
                
                temp = model.getElementAt(i, 11).toString();
                v = Float.valueOf(temp);
                produktai[i].vitB6=dg*v.floatValue();
                
                temp = model.getElementAt(i, 12).toString();
                v = Float.valueOf(temp);
                produktai[i].vitB12=dg*v.floatValue(); 
                
                temp = model.getElementAt(i, 13).toString();
                v = Float.valueOf(temp);
                produktai[i].vitPP=dg*v.floatValue();
                 
                temp = model.getElementAt(i, 14).toString();
                v = Float.valueOf(temp);
                produktai[i].minCa=dg*v.floatValue();
                
                temp = model.getElementAt(i, 15).toString();
                v = Float.valueOf(temp);
                produktai[i].minNa=dg*v.floatValue();/*Marijus : Mg->Na*/
                
                temp = model.getElementAt(i, 16).toString();
                v = Float.valueOf(temp);
                produktai[i].minS=dg*v.floatValue();
                
                temp = model.getElementAt(i, 17).toString();
                v = Float.valueOf(temp);
                produktai[i].minP=dg*v.floatValue();/*Marijus : F->P*/
                
                temp = model.getElementAt(i, 18).toString();
                v = Float.valueOf(temp);
                produktai[i].minJ=dg*v.floatValue();
                
                temp = model.getElementAt(i, 21).toString();
                v = Float.valueOf(temp);
                produktai[i].price=dg*v.floatValue();
                
                temp = model.getElementAt(i, 22).toString();
                v = Float.valueOf(temp);
                produktai[i].liquid=dg*v.floatValue();
                
                temp = model.getElementAt(i, 19).toString();
                v = Float.valueOf(temp);
                if(v.floatValue() >= 0.0F && v.floatValue() < 11F)
                {
                    produktai[i].setTaste(v.floatValue());
                    continue;
                } else
                {
                    duomenuKlaida = true;
                    break;
                }
                               
            }
            catch(NumberFormatException _ex)
            {
                lblStatus.setText("Wrong data file.Error: " +_ex.toString()+"Error data line: "+j);
                duomenuKlaida = true;
            }
            break;
        }

    }
 /* ------------------------------------
  *  metodas init 
  *  Inicijuoja apleta, paruosia pradinius
  *  laukus ir duomenis, "nupiesia" appleto
  *  elementus
  * ------------------------------------ */
    public void init()
    {
        productCount = 0;
        txtfldVitaB2 = new JTextField();
        txtfldVitaB3 = new JTextField();
        txtfldVitaB6 = new JTextField();
        txtfldVitaB12 = new JTextField(); 
        txtfldVitaPP = new JTextField();
        txtfldMCA = new JTextField(); 
        txtfldMNa = new JTextField();
        txtfldMS = new JTextField(); 
        txtfldMP = new JTextField();
        txtfldMJ = new JTextField(); 
        JLabelB22 = new JLabel();
        JLabelB33 = new JLabel();
        JLabelB66=new JLabel(); //Natali
        JLabelB122=new JLabel();//Natali
        JLabelPP=new JLabel();//Natali
        JLabelCa2=new JLabel();//Natali
        JLabelNa2=new JLabel(); //Natali
        JLabelS2=new JLabel();//Natali
        JLabelP2=new JLabel();//Natali
        JLabelJ2=new JLabel();//Natali    
        duomenuKlaida = false;
        
        failas = "sandra02.txt";
        D = new JDialog();
        lblFailas = new JLabel("Iveskite duomenu failo varda");
        txtfldFailas = new JTextField("sandra02.txt");
        btnOK = new JButton("OK");
        tbdpnlBendras = new JTabbedPane();
        pnlDuomenys = new JPanel();
        scrlpnLentele = new JScrollPane();
        tblLentele = new JTable();
        lblLentelesPav = new JLabel();
        lblRedagavimas = new JLabel();
        lblName = new JLabel();
        txtfldName = new JTextField();
        lblPrice = new JLabel();
        txtfldPrice = new JTextField();
        lblCalories = new JLabel();
        txtfldCalories = new JTextField();
        lblProteins = new JLabel();
        txtfldProteins = new JTextField();
        lblFats = new JLabel();
        txtfldFats = new JTextField();
        lblCarbohydrates = new JLabel();
        txtfldCarbohydrates = new JTextField();        
        lblFluids = new JLabel();
        txtfldFluids = new JTextField();        
        lblTaste = new JLabel();
        cmbbxTaste = new JComboBox();
        btnLoad = new JButton();
        btnNew = new JButton();
        btnUpdate = new JButton();
        btnNext1 = new JButton();
        btnDelete = new JButton();
        chkbxDish = new JCheckBox();
        chkbxDay = new JCheckBox();
        lblDish = new JLabel();
        JLabel5 = new JLabel();
        JLabel6 = new JLabel();
        JLabel7 = new JLabel();
        JLabel8 = new JLabel();
        lblDay = new JLabel();
        txtfldVitaminC = new JTextField();
        txtfldVitaminA = new JTextField();
        txtfldMineralCa = new JTextField();
        txtfldMineralNa = new JTextField();
        pnlPageidavimai = new JPanel();
        txtfldWeight = new JTextField();
        lblWeight = new JLabel();
        btnNext2 = new JButton();
        cmbbxOptimization = new JComboBox();
        lblOptimization = new JLabel();
       

//NEED        
        // 2 panel - kur ko reikia
        initComponents();


//NEED END        
        lblImportance = new JLabel();
        cmbbxImportance = new JTextField();// JComboBox();
        JLabel9 = new JLabel();
        JLabel10 = new JLabel();
        JLabel11 = new JLabel();
        JLabel12 = new JLabel();
        JLabel13 = new JLabel();
        JLabel14 = new JLabel();
        JLabel15 = new JLabel();
        pnlRezultatai = new JPanel();
        JScrollPane1 = new JScrollPane();
        JTable1 = new JTable();
        JLabel1 = new JLabel();
        JLabel2 = new JLabel();
        JLabel3 = new JLabel();
        JLabel4 = new JLabel();
        lblCaloriesTotal = new JLabel();
        lblProteinsTotal = new JLabel();
        lblFatsTotal = new JLabel();
        lblCarbohydratesTotal = new JLabel();
        tblmdlLentele = new StringTableModel();

        cmbbxmdlTaste = new StringComboBoxModel();
        cmbbxmdlTaste = new StringComboBoxModel();
        cmbbxmdlProteinsW = new StringComboBoxModel();
        cmbbxmdlfatsW = new StringComboBoxModel();
        cmbbxmdlCarbohydratesW = new StringComboBoxModel();
        cmbbxmdlCaloriesW = new StringComboBoxModel();
        lineBorder1 = new LineBorder();
        tblmdlRezultatai = new StringTableModel();
        
        cmbbxmdlOptimize = new StringComboBoxModel();
        cmbbxmdlBias = new StringComboBoxModel();
        lblStatus = new JLabel();

        cmbbxmdlITaste = new StringComboBoxModel();
        cmbbxmdlITaste = new StringComboBoxModel();
        cmbbxmdlIPrice = new StringComboBoxModel();
        cmbbxmdlImportance = new StringComboBoxModel();

        cmbbxIAddTaste = new JComboBox();
        JLabelAddOnTaste = new JLabel();

//---------------------------------------------        
        Context.setApplet(this);
        getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
        getContentPane().setLayout(null);
        setSize(780, 650);
        getContentPane().add(tbdpnlBendras);
        tbdpnlBendras.setBounds(12, 12, 760, 560);
        pnlDuomenys.setLayout(null);
        tbdpnlBendras.add(pnlDuomenys);
        pnlDuomenys.setBounds(2, 27, 727, 474);
        pnlDuomenys.setVisible(false);
        scrlpnLentele.setVerticalScrollBarPolicy(22);
        scrlpnLentele.setHorizontalScrollBarPolicy(32);
        scrlpnLentele.setOpaque(true);
        pnlDuomenys.add(scrlpnLentele);
        scrlpnLentele.setBounds(10, 33, 708, 168);
        tblLentele.setModel(tblmdlLentele);
        scrlpnLentele.getViewport().add(tblLentele);
        tblLentele.setBounds(0, 0, 690, 0);
        lblLentelesPav.setText("Produktai");
        pnlDuomenys.add(lblLentelesPav);
        lblLentelesPav.setBounds(10, 9, 200, 12);
        
        lblRedagavimas.setText("Duomenu apie produkta ivedimas");
        pnlDuomenys.add(lblRedagavimas);
        lblRedagavimas.setBounds(20, 213, 300, 24);
        lblName.setText("Pavadinimas");
        pnlDuomenys.add(lblName);
        lblName.setForeground(new Color(102, 102, 153));
        lblName.setBounds(240, 249, 100, 24);
        pnlDuomenys.add(txtfldName);
        txtfldName.setBounds(320, 249, 130, 24);
        lblPrice.setText("Kaina");
        pnlDuomenys.add(lblPrice);
        lblPrice.setBounds(22, 280, 100, 24);
        pnlDuomenys.add(txtfldPrice);
        txtfldPrice.setBounds(130, 280, 50, 24);
        lblCalories.setText("Kalorijos");
        pnlDuomenys.add(lblCalories);
        lblCalories.setBounds(22, 370, 96, 24);
        pnlDuomenys.add(txtfldCalories);
        txtfldCalories.setBounds(130, 370, 50, 24);
        lblProteins.setText("Baltymai");
        pnlDuomenys.add(lblProteins);
        lblProteins.setBounds(22, 310, 96, 24);
        pnlDuomenys.add(txtfldProteins);
        txtfldProteins.setBounds(130, 310, 50, 24);
        lblFats.setText("Riebalai");
        pnlDuomenys.add(lblFats);
        lblFats.setBounds(22, 340, 96, 24);
        pnlDuomenys.add(txtfldFats);
        txtfldFats.setBounds(130, 340, 50, 24);
        lblCarbohydrates.setText("Angliavandeniai");
        pnlDuomenys.add(lblCarbohydrates);
        lblCarbohydrates.setBounds(22, 400, 96, 24);
        pnlDuomenys.add(txtfldCarbohydrates);
        txtfldCarbohydrates.setBounds(130, 400, 50, 24);        
        lblFluids.setText("Skysčiai");
        pnlDuomenys.add(lblFluids);
        lblFluids.setBounds(22, 430, 96, 24);
        pnlDuomenys.add(txtfldFluids);
        txtfldFluids.setBounds(130, 430, 50, 24); 
        lblTaste.setText("Skonis *");
        pnlDuomenys.add(lblTaste);
        lblTaste.setBounds(530, 400, 110, 24);
        cmbbxTaste.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        pnlDuomenys.add(cmbbxTaste);
        cmbbxTaste.setBounds(620, 400, 50, 24);
        btnLoad.setText("Duomenu ivedimas is failo");
        btnLoad.setActionCommand("Atidaryti faila");
        pnlDuomenys.add(btnLoad);
        btnLoad.setBounds(10, 500, 200, 24);
        btnNew.setText("Naujas produktas");
        btnNew.setActionCommand("Naujas produktas");
        pnlDuomenys.add(btnNew);
        btnNew.setBounds(215, 500, 150, 24);
        btnUpdate.setText("Atnaujinti/Irasyti");
        btnUpdate.setActionCommand("Atnaujinti produkta");
        pnlDuomenys.add(btnUpdate);
        btnUpdate.setBounds(370, 500, 150, 24);
        btnNext1.setText("Toliau >>");
        btnNext1.setActionCommand("Toliau >>");
        pnlDuomenys.add(btnNext1);
        btnNext1.setBounds(664, 500, 85, 23);
        btnDelete.setText("Istrinti produkta");
        btnDelete.setActionCommand("Istrinti produkta");
        pnlDuomenys.add(btnDelete);
        btnDelete.setBounds(527, 500, 132, 24);
        pnlDuomenys.add(chkbxDish);
        chkbxDish.setForeground(new Color(102, 102, 153));
        chkbxDish.setBounds(340, 450, 72, 19);
        lblDish.setText("Patiekalas ?");
        pnlDuomenys.add(lblDish);
        lblDish.setBounds(240, 450, 90, 19);
        JLabel5.setText("Vitaminas A");
        pnlDuomenys.add(JLabel5);
        JLabel5.setBounds(210, 280, 98, 26);
        JLabel6.setText("Vitaminas E");
        pnlDuomenys.add(JLabel6);
        JLabel6.setBounds(210, 310, 100, 25);
        JLabel7.setText("Vitaminas C");
        pnlDuomenys.add(JLabel7);
        JLabel7.setBounds(210, 340, 107, 26);
        JLabel8.setText("Vitaminas B1");
        pnlDuomenys.add(JLabel8);
        JLabel8.setBounds(210, 370, 99, 27);
        pnlDuomenys.add(txtfldVitaminC);
        txtfldVitaminC.setBounds(300, 280, 50, 24);
        pnlDuomenys.add(txtfldVitaminA);
        txtfldVitaminA.setBounds(300, 310, 50, 24);
        pnlDuomenys.add(txtfldMineralCa);
        txtfldMineralCa.setBounds(300, 340, 50, 24);
        pnlDuomenys.add(txtfldMineralNa);
        txtfldMineralNa.setBounds(300, 370, 50, 24);        
        JLabelB22.setText("Vitaminas B2");
        pnlDuomenys.add(JLabelB22);
        JLabelB22.setBounds(210, 400, 98, 26);
        JLabelB33.setText("Vitaminas B3");
        pnlDuomenys.add(JLabelB33);
        JLabelB33.setBounds(370, 280, 100, 25);
        JLabelB66.setText("Vitaminas B6");
        pnlDuomenys.add(JLabelB66);
        JLabelB66.setBounds(370, 310, 107, 26);
        JLabelB122.setText("Vitaminas B12");
        pnlDuomenys.add(JLabelB122);
        JLabelB122.setBounds(370, 340, 99, 27);
        pnlDuomenys.add(txtfldVitaB2);
        txtfldVitaB2.setBounds(300, 400, 50, 24);
        pnlDuomenys.add(txtfldVitaB3);
        txtfldVitaB3.setBounds(460, 280, 50, 24);
        pnlDuomenys.add(txtfldVitaB6);
        txtfldVitaB6.setBounds(460, 310, 50, 24);
        pnlDuomenys.add(txtfldVitaB12);
        txtfldVitaB12.setBounds(460, 340, 50, 24);        
        JLabelPP.setText("Vitaminas PP");
        pnlDuomenys.add(JLabelPP);
        JLabelPP.setBounds(370, 370, 98, 26);     
        JLabelCa2.setText("Mikroel. Ca");
        pnlDuomenys.add(JLabelCa2);
        JLabelCa2.setBounds(370, 400, 100, 25);
        JLabelNa2.setText("Mikroel. Na");
        pnlDuomenys.add(JLabelNa2);
        JLabelNa2.setBounds(530, 280, 107, 26);
        JLabelS2.setText("Mikroel. S");
        pnlDuomenys.add(JLabelS2);
        JLabelS2.setBounds(530, 310, 99, 27);
        pnlDuomenys.add(txtfldVitaPP);
        txtfldVitaPP.setBounds(460,370, 50, 24);
        pnlDuomenys.add(txtfldMCA);
        txtfldMCA.setBounds(460, 400, 50, 24);
        pnlDuomenys.add(txtfldMNa);
        txtfldMNa.setBounds(620, 280, 50, 24);
        pnlDuomenys.add(txtfldMS);
        txtfldMS.setBounds(620, 310, 50, 24);        

        JLabelP2.setText("Mikroel. P");
        pnlDuomenys.add(JLabelP2);
        JLabelP2.setBounds(530, 340, 98, 26);
        JLabelJ2.setText("Mikroel. J");
        pnlDuomenys.add(JLabelJ2);
        JLabelJ2.setBounds(530, 370, 100, 25);
        pnlDuomenys.add(txtfldMP);
        txtfldMP.setBounds(620, 340, 50, 24);
        pnlDuomenys.add(txtfldMJ);
        txtfldMJ.setBounds(620, 370, 50, 24); 
        pnlPageidavimai.setLayout(null);
        tbdpnlBendras.add(pnlPageidavimai);
        pnlPageidavimai.setEnabled(false);
        pnlPageidavimai.setBounds(2, 27, 727, 474);
        pnlPageidavimai.setVisible(false);
        txtfldWeight.setText("70");
        pnlPageidavimai.add(txtfldWeight);
        txtfldWeight.setBounds(22, 171, 159, 24);
        lblWeight.setText("Zmogaus svoris, kg");
        pnlPageidavimai.add(lblWeight);
        lblWeight.setBounds(22, 146, 140, 35);
        btnNext2.setText("Toliau >>");
        btnNext2.setActionCommand("Toliau >>");
        pnlPageidavimai.add(btnNext2);
        btnNext2.setBounds(634, 441, 90, 24);
        cmbbxOptimization.setModel(cmbbxmdlOptimize);
        cmbbxOptimization.setBounds(22, 69, 161, 24);
        lblOptimization.setText("Optimizacijos parametrai");
        pnlPageidavimai.add(lblOptimization);
        lblOptimization.setBounds(10, 10, 150, 24);
        lblImportance.setText("Grozio Faktorius**"); 
        pnlPageidavimai.add(lblImportance);
        lblImportance.setBounds(22, 199, 240, 24);
        JLabel9.setText("jusu nuoziura");
        pnlPageidavimai.add(JLabel9);
        JLabel9.setBounds(22, 213, 162, 26);
        cmbbxImportance.setText("1");//new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        pnlPageidavimai.add(cmbbxImportance);
        cmbbxImportance.setBounds(22, 237, 159, 29);
        
        lblDay.setText("Ar norite sudaryti dieta savaitei?");
        pnlPageidavimai.add(lblDay);
        lblDay.setBounds(140, 450, 200, 19);
        pnlPageidavimai.add(chkbxDay);
        chkbxDay.setForeground(new Color(102, 102, 153));
        chkbxDay.setBounds(340, 450, 30, 19);
/*************************************
 * Produktai itraukliami tik pagal skoni
 * start marijus
 *****************************************/
        JLabelAddOnTaste.setText("Itraukti pagal skoni nuo");
        pnlPageidavimai.add(JLabelAddOnTaste);
        JLabelAddOnTaste.setBounds(22, 275, 162, 26);
        cmbbxIAddTaste.setModel(new DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        pnlPageidavimai.add(cmbbxIAddTaste);
        cmbbxIAddTaste.setBounds(22, 300, 159, 29);
 /*end*/
        pnlRezultatai.setLayout(null);
        pnlRezultatai.setEnabled(false);
        tbdpnlBendras.add(pnlRezultatai);
        pnlRezultatai.setBounds(2, 27, 727, 474);
        pnlRezultatai.setVisible(false);
        JScrollPane1.setVerticalScrollBarPolicy(22);
        JScrollPane1.setHorizontalScrollBarPolicy(32);
        JScrollPane1.setOpaque(true);
        pnlRezultatai.add(JScrollPane1);
        JScrollPane1.setBounds(10, 57, 408, 168);
        JTable1.setModel(tblmdlRezultatai);
        JTable1.setAutoResizeMode(4);
        JScrollPane1.getViewport().add(JTable1);
        JTable1.setBounds(0, 0, 390, 0);
        JLabel1.setText("Kaloriju kiekis (kcal):");
        pnlRezultatai.add(JLabel1);
        JLabel1.setBounds(15, 249, 150, 25);
        JLabel2.setText("Proteinu kiekis (g):");
        pnlRezultatai.add(JLabel2);
        JLabel2.setBounds(15, 276, 150, 25);
        JLabel3.setText("Riebalu kiekis (g):");
        pnlRezultatai.add(JLabel3);
        JLabel3.setBounds(15, 303, 150, 25);
        JLabel4.setText("Angliavandeniu kiekis (g):");
        pnlRezultatai.add(JLabel4);
        JLabel4.setBounds(15, 330, 150, 25);
        lblCaloriesTotal.setText("0");
        pnlRezultatai.add(lblCaloriesTotal);
        lblCaloriesTotal.setBounds(180, 249, 252, 24);
        lblProteinsTotal.setText("0");
        pnlRezultatai.add(lblProteinsTotal);
        lblProteinsTotal.setBounds(180, 276, 252, 24);
        lblFatsTotal.setText("0");
        pnlRezultatai.add(lblFatsTotal);
        lblFatsTotal.setBounds(180, 303, 252, 24);
        lblCarbohydratesTotal.setText("0");
        pnlRezultatai.add(lblCarbohydratesTotal);
        lblCarbohydratesTotal.setBounds(180, 330, 252, 24);
        tbdpnlBendras.setSelectedComponent(pnlDuomenys);
        tbdpnlBendras.setSelectedIndex(0);
        tbdpnlBendras.setTitleAt(0, "Produktai");
        tbdpnlBendras.setTitleAt(1, "Parametrai");
        tbdpnlBendras.setTitleAt(2, "Optimali dieta");
        tblmdlLentele.setColumnHeaders("Pavadinimas,Baltymai,Riebalai,Angliavandeniai,kCal,A,E,C,B1,B2,B3,B6,B12,PP,Ca,Na,S,P,J,Skonis,Patiekalas,Kaina,Skysčiai");
 
        tblmdlRezultatai.setColumnHeaders("Name, Amount");
        lblStatus.setBorder(lineBorder1);
        getContentPane().add(lblStatus);
        lblStatus.setFont(new Font("Dialog", 3, 12));
        lblStatus.setBounds(12, 560, 732, 60);
      
        D.setModal(true);
        D.setBounds(200, 200, 225, 170);
        D.setName("Data file name input");
        D.getContentPane().setLayout(null);
        lblFailas.setBounds(10, 10, 200, 30);
        D.getContentPane().add(lblFailas);
        txtfldFailas.setBounds(10, 40, 200, 30);
        D.getContentPane().add(txtfldFailas);
        btnOK.setBounds(80, 80, 60, 30);
        D.getContentPane().add(btnOK);
        SymMouse aSymMouse = new SymMouse();
        tblLentele.addMouseListener(aSymMouse);
        SymAction lSymAction = new SymAction();
        btnLoad.addActionListener(lSymAction);
        SymItem lSymItem = new SymItem();
        btnNext2.addActionListener(lSymAction);
        btnNext1.addActionListener(lSymAction);
        cmbbxOptimization.addItemListener(lSymItem);
        btnNew.addActionListener(lSymAction);
        btnUpdate.addActionListener(lSymAction);
        btnDelete.addActionListener(lSymAction);
        btnOK.addActionListener(lSymAction);
		// radioButton Vyras
		jrbtVyras = new JRadioButton("Vyras");
		jrbtVyras.setActionCommand("vyras");
		jrbtVyras.setBounds(10,35,70,16);
		pnlPageidavimai.add(jrbtVyras);
		jrbtVyras.addItemListener(lSymItem);
		// radioButton Moteris
		jrbtMoretis = new JRadioButton("Moteris");
		jrbtVyras.setActionCommand("moteris");
		jrbtMoretis.setBounds(10,55,70,16);
		pnlPageidavimai.add(jrbtMoretis);
		jrbtMoretis.addItemListener(lSymItem);
		// radioButton Vaikas
		jrbtVaikas = new JRadioButton("Vaikas");
		jrbtVaikas.setActionCommand("vaikas");
		jrbtVaikas.setBounds(10,75,70,16);
		pnlPageidavimai.add(jrbtVaikas);
		jrbtVaikas.addItemListener(lSymItem);
		// Radio grupe
		jrbtgrTipai = new ButtonGroup();
		jrbtgrTipai.add(jrbtVyras);
		jrbtgrTipai.add(jrbtMoretis);
		jrbtgrTipai.add(jrbtVaikas);
		
		// reikalavimu tekstas
		jReikalavimuTekstas = new JTextField();
		jReikalavimuTekstas.setBounds(140, 400, 600, 26);
		pnlPageidavimai.add(jReikalavimuTekstas);
		
		// skaiciavimo paklaidos invedimui
		jPaklaida = new JTextField();
		jPaklaida.setBounds(620, 20, 40, 26);
		pnlPageidavimai.add(jPaklaida);
		jPaklaida.setText("0.0001");
		
		jLabelPaklaida = new JLabel();
		jLabelPaklaida.setText("Skaičiavimo paklaida");
		pnlPageidavimai.add(jLabelPaklaida);
		jLabelPaklaida.setBounds(620, 5, 150, 13);
		
		// mygtukai
		jbtnTekstas = new JButton();
		jbtnTekstas.setText("Įvesti");
		jbtnTekstas.setActionCommand("IvestiTeksta");
		jbtnTekstas.setBounds(20,410,100, 26);
		jbtnTekstas.addActionListener(lSymAction);
		pnlPageidavimai.add(jbtnTekstas);
		
		// aktyvumo pasirinkimas
		cmbbxAktyvumas = new JComboBox();
		cmbbxAktyvumas.setModel(new DefaultComboBoxModel(new String[] { "1.5","1.7", "2.0", "2.2" }));
		pnlPageidavimai.add(cmbbxAktyvumas);
		cmbbxAktyvumas.setBounds(160,45,50, 26);
		cmbbxAktyvumas.addItemListener(lSymItem);
		
		// amziaus pasirinkimas suaugusiems
		cmbbxAmzius = new JComboBox();
		cmbbxAmzius.setModel(new DefaultComboBoxModel(new String[] { "19-34","35-49", "50-64" }));
		pnlPageidavimai.add(cmbbxAmzius);
		cmbbxAmzius.setBounds(90,45,60, 26);
		cmbbxAmzius.addItemListener(lSymItem);
		
		// vaiko amziaus pasirinkimas
		cmbbxVaikoAmzius = new JComboBox();
		cmbbxVaikoAmzius.setModel(new DefaultComboBoxModel(new String[] { "1-3","4-6", "7-10", "11-14 berniukai", "11-14 mergaitės", "15-18 berniukai", "15-18 mergaitės" }));
		pnlPageidavimai.add(cmbbxVaikoAmzius);
		cmbbxVaikoAmzius.setBounds(90,75,100, 26);
		cmbbxVaikoAmzius.addItemListener(lSymItem);
		
		jLabelAktyvumas = new JLabel();
		jLabelAktyvumas.setText("Aktyvumas");
		pnlPageidavimai.add(jLabelAktyvumas);
		jLabelAktyvumas.setBounds(160, 25, 70, 20);
		
		jLabelAmzius = new JLabel();
		jLabelAmzius.setText("Amžius");
		pnlPageidavimai.add(jLabelAmzius);
		jLabelAmzius.setBounds(90, 25, 70, 20);
		
		tfldPapildomi = new JTextField();
		tfldPapildomi.setBounds(140, 370, 600, 26);
		pnlPageidavimai.add(tfldPapildomi);
		
		
		ikrautiPapildomuReikalavimuSarasa_V("papild_V");
		ikrautiPapildomuReikalavimuSarasa_M("papild_M");
		jcbPapildomosSalygos_V = new JComboBox(sPavPapildomi_V);
		jcbPapildomosSalygos_V.addItemListener(lSymItem);
		pnlPageidavimai.add(jcbPapildomosSalygos_V);
		jcbPapildomosSalygos_V.setBounds(430, 5, 170, 20);
		jcbPapildomosSalygos_V.setEnabled(false);
		
		jcbPapildomosSalygos_M = new JComboBox(sPavPapildomi_M);
		jcbPapildomosSalygos_M.addItemListener(lSymItem);
		pnlPageidavimai.add(jcbPapildomosSalygos_M);
		jcbPapildomosSalygos_M.setBounds(430, 25, 170, 20);
		jcbPapildomosSalygos_M.setEnabled(false);
		
		chkbxPapildoma = new JCheckBox();
		chkbxPapildoma.setSelected(true);
		chkbxPapildoma.setVisible(false);
		chkbxPapildoma.setBounds(230, 30, 20, 20);
		pnlPageidavimai.add(chkbxPapildoma);
		chkbxPapildoma.addItemListener(lSymItem);
	
		jLabelPapildoma = new JLabel();
		jLabelPapildoma.setBounds(280, 5, 300, 20);
		jLabelPapildoma.setText("Papildomi reikalavimai");
		pnlPageidavimai.add(jLabelPapildoma);
		
		jLabelIvairovesIvedimas = new JLabel();
		jLabelIvairovesIvedimas.setText("Maisto ivairovė");
		jLabelIvairovesIvedimas.setBounds(22, 100, 100, 20);
		pnlPageidavimai.add(jLabelIvairovesIvedimas);
		
		jIvairove = new JTextField();
		jIvairove.setText("1.0");
		jIvairove.setBounds(22, 125, 40, 20);
		pnlPageidavimai.add(jIvairove);
		
		jLabelIvairovesSprendimas = new JLabel();
		jLabelIvairovesSprendimas.setText("Dietos maisto ivairumas:");
		pnlRezultatai.add(jLabelIvairovesSprendimas);
		jLabelIvairovesSprendimas.setBounds(15, 418, 152, 24);
		
		jLabelIvairovesSprendimas2 = new JLabel();
		jLabelIvairovesSprendimas2.setText("0");
		pnlRezultatai.add(jLabelIvairovesSprendimas2);
		jLabelIvairovesSprendimas2.setBounds(180, 418, 252, 24);
		//amziaus pasirinkimas

        initTotals();
        jrbtVyras.setSelected(true);
    }
 /* ------------------------------------
  *  metodas tblLentele_mouseClicked
  *  atvaizduoja lenteleje pazymeta produkta 
  *  i kitus appleto elementus
  * ------------------------------------ */
    void tblLentele_mouseClicked(MouseEvent event)
    {
        txtfldName.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 0).toString());
        
        txtfldCalories.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 4).toString());
        txtfldProteins.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 1).toString());
        txtfldFats.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 2).toString());
        txtfldCarbohydrates.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 3).toString());
        txtfldVitaminC.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 5).toString());
        txtfldVitaminA.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 6).toString());
        txtfldMineralCa.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 7).toString());
        txtfldMineralNa.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 8).toString());
        txtfldVitaB2.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 9).toString());
        txtfldVitaB3.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 10).toString());
        txtfldVitaB6.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 11).toString());
        txtfldVitaB12.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 12).toString());
        txtfldVitaPP.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 13).toString());
        txtfldMCA.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 14).toString());
        txtfldMNa.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 15).toString());
        txtfldMS.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 16).toString());
        txtfldMP.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 17).toString());
        txtfldMJ.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 18).toString());        
        cmbbxTaste.setSelectedItem(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 19));
        Integer tt = Integer.valueOf(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 20).toString());
        if(tt.intValue() == 1)
            chkbxDish.setSelected(true);
        else
            chkbxDish.setSelected(false);
        txtfldPrice.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 21).toString());
        txtfldFluids.setText(tblmdlLentele.getValueAt(tblLentele.getSelectedRow(), 22).toString());
   }

   private void initComponents() {
        ReikiaKal = new JTextField();
        ReikiaAngl = new JTextField();
        ReikiaBalt = new JTextField();
        ReikiaRieb = new JTextField();
        ReikiaVitA = new JTextField();
        ReikiaVitB1 = new JTextField();
        ReikiaVitB2 = new JTextField();
        ReikiaVitB3 = new JTextField();
        ReikiaVitB6 = new JTextField();
        ReikiaVitB12 = new JTextField();        
        ReikiaVitC = new JTextField();
        ReikiaVitE = new JTextField();
        ReikiaVitPP = new JTextField();                
        ReikiaFosf = new JTextField();
        ReikiaSer = new JTextField();
        ReikiaNatr = new JTextField();
        ReikiaKalc = new JTextField();
        ReikiaJ = new JTextField();
        ReikiaLiquid = new JTextField();
        
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();
        jLabel4 = new JLabel();
        jLabel5 = new JLabel();
        jLabel6 = new JLabel();
        jLabel7 = new JLabel();
        jLabel8 = new JLabel();
        jLabel9 = new JLabel();
        jLabel10 = new JLabel();
        jLabel11 = new JLabel();
        jLabel12 = new JLabel();
        jLabel13 = new JLabel();
        jLabel14 = new JLabel();
        jLabel15 = new JLabel();
        jLabel16 = new JLabel();
        jLabel17 = new JLabel();
        jLabel18 = new JLabel();
        jLabel19 = new JLabel();
        jLabel20 = new JLabel();        
        jLabel21 = new JLabel();   
        jLabel22 = new JLabel();   
        jLabel23 = new JLabel();
        getContentPane().setLayout(null);

        pnlPageidavimai.setLayout(null);
/*------------- normos zmogaus mases kilogramui --------------*/
        jLabel17.setText("Zmogui vienam mases kg reikia:");
        pnlPageidavimai.add(jLabel17);
        jLabel17.setBounds(240,50, 240, 20);

        
        jLabel1.setText("Kaloriju kiekis, kCal");
        pnlPageidavimai.add(jLabel1);
        jLabel1.setBounds(240, 70, 120, 20);
        ReikiaKal.setText("34.7");
        pnlPageidavimai.add(ReikiaKal);
        ReikiaKal.setBounds(240, 90, 80, 20);

        jLabel2.setText("Angliavandeniai, g");
        pnlPageidavimai.add(jLabel2);
        jLabel2.setBounds(360, 70, 120, 20);
        ReikiaAngl.setText("6.5");
        pnlPageidavimai.add(ReikiaAngl);
        ReikiaAngl.setBounds(360, 90, 80, 20);

        jLabel4.setText("Baltymu kiekis, g");
        pnlPageidavimai.add(jLabel4);
        jLabel4.setBounds(480, 70, 120, 20);
        ReikiaBalt.setText("1.3");
        pnlPageidavimai.add(ReikiaBalt);
        ReikiaBalt.setBounds(480, 90, 80, 20);
        
        jLabel5.setText("Riebalu kiekis, g");
        pnlPageidavimai.add(jLabel5);
        jLabel5.setBounds(600, 70, 110, 20);
        ReikiaRieb.setText("1.3");
        pnlPageidavimai.add(ReikiaRieb);
        ReikiaRieb.setBounds(600, 90, 80, 20);

/*------------- zmogaus normos parai --------------------------*/

        jLabel18.setText("Zmogaus paros norma:");
        pnlPageidavimai.add(jLabel18);
        jLabel18.setBounds(240,120, 200, 20);
 /*VITAMINAI*/       
        jLabel19.setText("Vitaminai");
        pnlPageidavimai.add(jLabel19);
        jLabel19.setBounds(260,140, 200, 20);
        
/*1*/        jLabel6.setText("Vitaminas A, mg");
        pnlPageidavimai.add(jLabel6);
        jLabel6.setBounds(240, 160, 110, 20);        
        ReikiaVitA.setText("0.8");
        pnlPageidavimai.add(ReikiaVitA);
        ReikiaVitA.setBounds(240, 180, 80, 20);

/*2*/        jLabel9.setText("Vitamimas B1, mg");
        pnlPageidavimai.add(jLabel9);
        jLabel9.setBounds(240, 200, 110, 20);
        ReikiaVitB1.setText("1.5");
        pnlPageidavimai.add(ReikiaVitB1);
        ReikiaVitB1.setBounds(240, 220, 80, 20);
                
/*3*/        jLabel10.setText("Vitaminas B2, mg");
        pnlPageidavimai.add(jLabel10);
        jLabel10.setBounds(240, 240, 110, 20);
        ReikiaVitB2.setText("1.7");
        pnlPageidavimai.add(ReikiaVitB2);
        ReikiaVitB2.setBounds(240, 260, 80, 20);
                
/*4*/        jLabel11.setText("Vitaminas B3, mg");
        pnlPageidavimai.add(jLabel11);
        jLabel11.setBounds(240, 280, 110, 20);
        ReikiaVitB3.setText("1.8");
        pnlPageidavimai.add(ReikiaVitB3);
        ReikiaVitB3.setBounds(240, 300, 80, 20);
                
/*5*/       jLabel12.setText("Vitaminas B6, mg");
        pnlPageidavimai.add(jLabel12);
        jLabel12.setBounds(360, 160, 110, 20);
        ReikiaVitB6.setText("2");
        pnlPageidavimai.add(ReikiaVitB6);
        ReikiaVitB6.setBounds(360, 180, 80, 20);
        
/*6*/        jLabel8.setText("Vitaminas B12, mkrg");
        pnlPageidavimai.add(jLabel8);
        jLabel8.setBounds(360, 200, 120, 20);
        ReikiaVitB12.setText("6");
        pnlPageidavimai.add(ReikiaVitB12);
        ReikiaVitB12.setBounds(360, 220, 80, 20);
        
/*7*/       jLabel7.setText("Vitaminas C, mg");
        pnlPageidavimai.add(jLabel7);
        jLabel7.setBounds(360, 240, 110, 20);
        ReikiaVitC.setText("60");
        pnlPageidavimai.add(ReikiaVitC);
        ReikiaVitC.setBounds(360, 260, 80, 20);                
        
/*8*/        jLabel3.setText("Vitaminas E, mg");
        pnlPageidavimai.add(jLabel3);
        jLabel3.setBounds(360, 280, 110, 20);
        ReikiaVitE.setText("10");
        pnlPageidavimai.add(ReikiaVitE);
        ReikiaVitE.setBounds(360, 300, 80, 20);
    /******papildymai******/        
/*9 PP nebuvo*/        
        jLabel21.setText("Vitaminas PP, mg");
        pnlPageidavimai.add(jLabel21);
        jLabel21.setBounds(240, 320, 110, 20);
        ReikiaVitPP.setText("17");
        pnlPageidavimai.add(ReikiaVitPP);
        ReikiaVitPP.setBounds(240, 340, 80, 20);
        
 /*MIKROELEMENTAI*/ 
        jLabel20.setText("Mikroelementai");
        pnlPageidavimai.add(jLabel20);
        jLabel20.setBounds(500,140, 200, 20);               
/*1*/        jLabel16.setText("Fosforas, mg");
        pnlPageidavimai.add(jLabel16);
        jLabel16.setBounds(490, 160, 110, 20);
        ReikiaFosf.setText("900");
        pnlPageidavimai.add(ReikiaFosf);
        ReikiaFosf.setBounds(490, 180, 80, 20);
        
/*2*/        jLabel15.setText("Mikroel. S, mg");
        pnlPageidavimai.add(jLabel15);
        jLabel15.setBounds(490, 200, 110, 20);
        ReikiaSer.setText("1000");
        pnlPageidavimai.add(ReikiaSer);
        ReikiaSer.setBounds(490, 220, 80, 20);
        
/*3*/        jLabel14.setText("Mikroel. Na, mg");
        pnlPageidavimai.add(jLabel14);
        jLabel14.setBounds(490, 240, 110, 20);
        ReikiaNatr.setText("1500");
        pnlPageidavimai.add(ReikiaNatr);
        ReikiaNatr.setBounds(490, 260, 80, 20);
        
/*4*/        jLabel13.setText("Mikroel. Ca, mg");
        pnlPageidavimai.add(jLabel13);
        jLabel13.setBounds(490, 280, 110, 20);
        ReikiaKalc.setText("1000");
        pnlPageidavimai.add(ReikiaKalc);
        ReikiaKalc.setBounds(490, 300, 80, 20);
    /******papildymai******/        
/*5 J nebuvo*/        
        jLabel22.setText("Mikroel. J, mg");
        pnlPageidavimai.add(jLabel22);
        jLabel22.setBounds(610, 160, 110, 20);
        ReikiaJ.setText("17");
        pnlPageidavimai.add(ReikiaJ);
        ReikiaJ.setBounds(610, 180, 80, 20); 
        
        jLabel23.setText("Skysčiai, ml");
        pnlPageidavimai.add(jLabel23);
        jLabel23.setBounds(610, 200, 110, 20);
        ReikiaLiquid.setText("2000");
        pnlPageidavimai.add(ReikiaLiquid);
        ReikiaLiquid.setBounds(610, 220, 80, 20);         
   } 
  /* ------------------------------------
  *  metodas initTotals()
  *  inicijuoja atsakymu laukus
  * ------------------------------------ */  
     private void initTotals() {
       /*Papildomi atsakymai*/
    lblPriceTotal = new JLabel();
    lblPriceTTlbl = new JLabel();
    lblPriceTotalS = new JLabel();
    lblPriceTTlblS = new JLabel();
        
    lblVitATotal = new JLabel();
    lblVitCTotal = new JLabel();
    lblVitB1Total = new JLabel();   
    lblVitB2Total = new JLabel();
    lblVitB3Total = new JLabel();
    lblVitB6Total = new JLabel();
    lblVitB12Total = new JLabel();
    lblVitETotal = new JLabel();
    lblVitPPTotal = new JLabel();
    lblMinCaTotal = new JLabel();
    lblMinNaTotal = new JLabel();
    lblMinSTotal = new JLabel();
    lblMinPTotal = new JLabel();
    lblMinJTotal = new JLabel();
    lblMinLiquidTotal = new JLabel();
    
    lblVitATTlbl = new JLabel();
    lblVitB1TTlbl = new JLabel();
    lblVitB2TTlbl = new JLabel();
    lblVitB3TTlbl = new JLabel();
    lblVitB6TTlbl = new JLabel();
    lblVitB12TTlbl = new JLabel();
    lblVitCTTlbl = new JLabel();
    lblVitETTlbl = new JLabel();
    lblVitPPTTlbl = new JLabel();
    lblMinCaTTlbl = new JLabel();
    lblMinNaTTlbl = new JLabel();
    lblMinSTTlbl = new JLabel();
    lblMinPTTlbl = new JLabel();
    lblMinJTTlbl = new JLabel();
    lblMinLiquidTTlbl = new JLabel();
    //---------
    lblPriceTTlbl.setText("Dietos kaina(reali) Lt:");
    pnlRezultatai.add(lblPriceTTlbl);
    lblPriceTTlbl.setBounds(15, 357, 252, 24);
    
    lblPriceTotal.setText("0");
    pnlRezultatai.add(lblPriceTotal);
    lblPriceTotal.setBounds(180, 357, 200, 24);
    //---------
    lblPriceTTlblS.setText("Dietos kaina(subj.) Lt:");
    pnlRezultatai.add(lblPriceTTlblS);
    lblPriceTTlblS.setBounds(15, 384, 252, 24);
    
    lblPriceTotalS.setText("0");
    pnlRezultatai.add(lblPriceTotalS);
    lblPriceTotalS.setBounds(180, 384, 200, 24);
//--------------------------
    lblVitATTlbl.setText("Vitamino A (mg) :");
    pnlRezultatai.add(lblVitATTlbl);
    lblVitATTlbl.setBounds( 480, 27, 200, 24);
    
    lblVitATotal.setText("0");
    pnlRezultatai.add(lblVitATotal);
    lblVitATotal.setBounds( 640, 27, 200, 24);
//-----    
    lblVitB1TTlbl.setText("Vitamino B1 (mg) :");
    pnlRezultatai.add(lblVitB1TTlbl);
    lblVitB1TTlbl.setBounds(480, 54, 200, 24);
    
    lblVitB1Total.setText("0");
    pnlRezultatai.add(lblVitB1Total);
    lblVitB1Total.setBounds(640, 54, 252, 24);
//---        
    lblVitB2TTlbl.setText("Vitamino B2 (mg) :");
    pnlRezultatai.add(lblVitB2TTlbl);
    lblVitB2TTlbl.setBounds(480,81, 200, 24);

    lblVitB2Total.setText("0");
    pnlRezultatai.add(lblVitB2Total);
    lblVitB2Total.setBounds(640,81, 200, 24);
//---
    lblVitB3TTlbl.setText("Vitamino B3 (mg) :");
    pnlRezultatai.add(lblVitB3TTlbl);
    lblVitB3TTlbl.setBounds(480, 108, 200, 24);
    
    lblVitB3Total.setText("0");
    pnlRezultatai.add(lblVitB3Total);
    lblVitB3Total.setBounds(640, 108, 200, 24);
//---        
    lblVitB6TTlbl.setText("Vitamino B6 (mg) :");
    pnlRezultatai.add(lblVitB6TTlbl);
    lblVitB6TTlbl.setBounds(480, 135, 200, 24);
    
    lblVitB6Total.setText("0");
    pnlRezultatai.add(lblVitB6Total);
    lblVitB6Total.setBounds(640, 135, 200, 24);
//---    
    lblVitB12TTlbl.setText("Vitamino B12(mkrg):");
    pnlRezultatai.add(lblVitB12TTlbl);
    lblVitB12TTlbl.setBounds(480, 162, 200, 24);
    
    lblVitB12Total.setText("0");
    pnlRezultatai.add(lblVitB12Total);
    lblVitB12Total.setBounds(640, 162, 200, 24);
//---        
    lblVitCTTlbl.setText("Vitamino C (mg) :");
    pnlRezultatai.add(lblVitCTTlbl);
    lblVitCTTlbl.setBounds( 480, 189 , 200, 24); 
    
    lblVitCTotal.setText("0");
    pnlRezultatai.add(lblVitCTotal);
    lblVitCTotal.setBounds( 640, 189 , 200, 24);
//---
    lblVitETTlbl.setText("Vitamino E (mg) :");
    pnlRezultatai.add(lblVitETTlbl);
    lblVitETTlbl.setBounds(480, 216, 200, 24);
    
    lblVitETotal.setText("0");
    pnlRezultatai.add(lblVitETotal);
    lblVitETotal.setBounds(640, 216, 200, 24);
//---           
    lblVitPPTTlbl.setText("Vitamino PP (mg) :");
    pnlRezultatai.add(lblVitPPTTlbl);
    lblVitPPTTlbl.setBounds(480, 243, 200, 24);
    
    lblVitPPTotal.setText("0");
    pnlRezultatai.add(lblVitPPTotal);
    lblVitPPTotal.setBounds(640, 243, 200, 24);
//---
    lblMinCaTTlbl.setText("Mikroelemento Ca (mg) :");
    pnlRezultatai.add(lblMinCaTTlbl);
    lblMinCaTTlbl.setBounds(480, 270, 200, 24);
    
    lblMinCaTotal.setText("0");
    pnlRezultatai.add(lblMinCaTotal);
    lblMinCaTotal.setBounds(640, 270, 200, 24);    
//---    
    lblMinNaTTlbl.setText("Mikroelemento Na (mg) :");
    pnlRezultatai.add(lblMinNaTTlbl);
    lblMinNaTTlbl.setBounds(480, 297, 200, 24);
    
    lblMinNaTotal.setText("0");
    pnlRezultatai.add(lblMinNaTotal);
    lblMinNaTotal.setBounds(640, 297, 200, 24);
//---                 
    lblMinSTTlbl.setText("Mikroelemento S (mg) :");
    pnlRezultatai.add(lblMinSTTlbl);
    lblMinSTTlbl.setBounds(480, 324, 200, 24);
    
    lblMinSTotal.setText("0");
    pnlRezultatai.add(lblMinSTotal);
    lblMinSTotal.setBounds(640, 324, 200, 24);
//---        
    lblMinPTTlbl.setText("Mikroelemento P (mg) :");
    pnlRezultatai.add(lblMinPTTlbl);
    lblMinPTTlbl.setBounds(480, 351, 200, 24);
    
    lblMinPTotal.setText("0");
    pnlRezultatai.add(lblMinPTotal);
    lblMinPTotal.setBounds(640, 351, 200, 24);
//---    
    lblMinJTTlbl.setText("Mikroelemento J (mg) :");
    pnlRezultatai.add(lblMinJTTlbl);
    lblMinJTTlbl.setBounds(480, 378, 200, 24);
    
    lblMinJTotal.setText("0");
    pnlRezultatai.add(lblMinJTotal);
    lblMinJTotal.setBounds(640, 378, 200, 24);     
//--- 
    lblMinLiquidTTlbl.setText("Skysčiai (ml) :");
    pnlRezultatai.add(lblMinLiquidTTlbl);
    lblMinLiquidTTlbl.setBounds(480, 405, 200, 24);   
    
    lblMinLiquidTotal.setText("0");
    pnlRezultatai.add(lblMinLiquidTotal);
    lblMinLiquidTotal.setBounds(640, 405, 200, 24); 
   /*end*/ 
   }  
}
