Sqlite browser burdan indirin
Sql jdbc burdan indirin
Sqlite Örneğini indir

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;//Veri tabanına Bağlantı yapmak için kullandığımız kütüphane 

public class Calistir  implements ActionListener,ListSelectionListener {
	
	JTextField[] jtext_gun;
	 JLabel[] jlb;
	 String[] lbltitle= {"Ad:","SoyAd:","Yas:"};
	 JButton jbtn_gun;
	 JPanel jpn_gun,jpnlb_gun;
	 int yas_gun=-1; 
     JFrame frm,frmgun;
	 JList jlist[],jlistyas;
	 DefaultListModel<String> dlm[];
	 DefaultListModel<Integer> dlmyas,dlmidler;
	 JTextField[] jtext;
	 String[] jbtntitle= {"Ekle","Sil","Güncelle"};
	 JButton[] jbtn;
	 JPanel jpn[],jpnyas;
	 JScrollPane scjpn[],scjpnyas;
	 public Calistir() {
       frm=new JFrame("Sqlite Bağlanti");
       frm.setSize(400, 500);
       frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frm.setLayout(new FlowLayout());
       
       jpn=new JPanel[2];
       dlm=new DefaultListModel[jpn.length];
       dlmidler=new DefaultListModel<Integer>();
       jlist=new JList[dlm.length];
       scjpn=new JScrollPane[jlist.length];
       jbtn=new JButton[3];
       jtext=new JTextField[3];
       
       for(int i=0;i<jpn.length;i++)
       {
    	   jpn[i]=new JPanel();
    	   jpn[i].setPreferredSize(new Dimension(100,400));
    	   jpn[i].setLayout(new FlowLayout());
    	   dlm[i]=new DefaultListModel<String>();
    	   jlist[i]=new JList<String>(dlm[i]);
    	   jlist[i].addListSelectionListener(this);
    	   scjpn[i]=new JScrollPane(jlist[i]);
    	   scjpn[i].setPreferredSize(new Dimension(100,300));
    	   jpn[i].add(scjpn[i]);
    	   frm.add(jpn[i]);   
       }
    	  jpnyas=new JPanel();
    	  jpnyas.setPreferredSize(new Dimension(100,400));
    	  jpnyas.setLayout(new FlowLayout());
   	      dlmyas=new DefaultListModel<Integer>();
   	      jlistyas=new JList<Integer>(dlmyas);
   	      jlistyas.addListSelectionListener(this);
   	      scjpnyas=new JScrollPane(jlistyas);
   	      scjpnyas.setPreferredSize(new Dimension(100,300));
   	      jpnyas.add(scjpnyas);
   	     
   	      for(int i=0;i<jpn.length;i++)//JButtonlar ve JTextField lar oluşturulup panele atılıyor 
   	      {   jtext[i]=new JTextField();
   	          jtext[i].setPreferredSize(new Dimension(100,20));
   	    	  jbtn[i]=new JButton(jbtntitle[i]);
   	    	  jbtn[i].setPreferredSize(new Dimension(100,20));
   	    	  jbtn[i].addActionListener(this);
   	    	  jbtn[i].setActionCommand(jbtntitle[i]);
   	    	  jpn[i].add(jtext[i]);
   	    	  jpn[i].add(jbtn[i]);
   	    	  if(i==jpn.length-1)
   	    	  { 
   	          jtext[2]=new JTextField();
   	          jtext[2].setPreferredSize(new Dimension(100,20));
   	    	  jbtn[2]=new JButton(jbtntitle[2]);
   	    	  jbtn[2].setPreferredSize(new Dimension(100,20));
   	    	  jbtn[2].addActionListener(this);
   	    	  jbtn[2].setActionCommand(jbtntitle[2]);
   	    	  jpnyas.add(jtext[2]);
   	    	  jpnyas.add(jbtn[2]);
   	    	  }
   	      }
   	   frm.add(jpnyas); 
   	   verigetir();
       frm.setVisible(true);
	}
	 public void  KGuncelle(int secilen)
		{   frm.setVisible(false);
			frmgun=new JFrame("Kişi Güncelle");
			frmgun.setSize(300, 300);
			frmgun.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			frmgun.setLayout(new FlowLayout());
	
			jpn_gun=new JPanel();
			jpn_gun.setPreferredSize(new Dimension(100,150));
			jpn_gun.setLayout(new FlowLayout());
			
			jpnlb_gun=new JPanel();
			jpnlb_gun.setPreferredSize(new Dimension(40,150));
			jpnlb_gun.setLayout(new FlowLayout());
			
			
			jlb=new JLabel[3];
			jtext_gun=new JTextField[jlb.length];
			
			for(int i=0;i<lbltitle.length;i++)
			{
				jlb[i]=new JLabel(lbltitle[i]);
				jlb[i].setPreferredSize(new Dimension(40,20)); 
				jlb[i].setHorizontalAlignment(JLabel.RIGHT);
			    jtext_gun[i]=new JTextField();
			    jtext_gun[i].setPreferredSize(new Dimension(100,20));
			    jpnlb_gun.add(jlb[i]);
			    jpn_gun.add(jtext_gun[i]);	
			}
			for(int i=0;i<dlm.length;i++)
			     jtext_gun[i].setText(dlm[i].getElementAt(secilen));
			     jtext_gun[2].setText(dlmyas.getElementAt(secilen).toString());
			     
			
			jbtn_gun=new JButton("Kaydet");
			jbtn_gun.setPreferredSize(new Dimension(100,20));
			jbtn_gun.addActionListener(this);
			jbtn_gun.setActionCommand("Kaydet");
			jpn_gun.add(jbtn_gun);
			frmgun.add(jpnlb_gun);
			frmgun.add(jpn_gun);
			frmgun.setVisible(true);
		}
		
	public static void main(String[] args) {
		
        new Calistir();
		
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
	    int yas=sayicevir(jtext[2].getText());
	    int secilen=jlist[0].getSelectedIndex();
		if(arg0.getActionCommand().equals("Ekle")&&jtext_kontrol(jtext)&&yas!=-1)
		{
			for(int i=0;i<dlm.length;i++)
			      dlm[i].addElement(jtext[i].getText());
			dlmyas.addElement(yas);
			
			ekle(jtext,yas);//Fonskiyonu çağrıyorum eklemesi için
			for(int i=0;i<jtext.length;i++)
				jtext[i].setText("");
		  verigetir();
		}
		else if(arg0.getActionCommand().equals("Sil")&&secilen>-1) {
			sil(dlm,secilen);
			for(int i=0;i<dlm.length;i++)
	    		     dlm[i].removeElementAt(secilen);
		           dlmyas.removeElementAt(secilen);	
		}
		else if(arg0.getActionCommand().equals("Güncelle")&&secilen>-1){
               frm.setVisible(false);// Bu formu gizle
              KGuncelle(secilen);//guncelle fromunu aç
			   }
			   else if(arg0.getActionCommand().equals("Kaydet")&&jtext_kontrol(jtext_gun))
			   {  
				   yas_gun=sayicevir(jtext_gun[2].getText());
				   if(yas_gun!=-1)
				   {  
			          frm.setVisible(true);//Eğer girilen bilgiler doğruysa frm göster
			          frmgun.dispose();//guncelle formunu yoket
			      for(int i=0;i<dlm.length;i++)
				      dlm[i].removeElementAt(secilen);
			          dlmyas.removeElementAt(secilen);   
			          dlm[0].insertElementAt(jtext_gun[0].getText(),secilen);
			          dlm[1].insertElementAt(jtext_gun[1].getText(),secilen);
			          dlmyas.insertElementAt(yas_gun,secilen);
				   guncelle(secilen);
				   verigetir(); 				
				   }
			    }
}
	 public boolean jtext_kontrol(JTextField[] jtxt)
	{
		 boolean durum=true;
		 for(int i=0;i<jtxt.length;i++)
		 {
			 if(jtxt[i].getText().length()==0)
			 {
				 durum=false;
				 break;
			 }
		 }
   return durum;  
	}
  public int sayicevir(String s)
   {  int yas=0;
     
      try {
    	  yas=Integer.parseInt(s);
      }catch(Exception ex)
      {
    	  yas=-1;
      }
   return yas;	   
   }
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
	    JList secilen=(JList)arg0.getSource();
	    for(int i=0;i<jlist.length;i++)
	    	  jlist[i].setSelectedIndex(secilen.getSelectedIndex());
	    jlistyas.setSelectedIndex(secilen.getSelectedIndex());
	}
//Veri Tabanı İşlemleri
Connection baglanti=null;
public void baglan()
{
     try {
    	 Class.forName("org.sqlite.JDBC");//Sql sınıfının hızlı yüklenmesi için
    	 baglanti=DriverManager.getConnection("jdbc:sqlite:Deneme.db");
     }catch(Exception ex)
     {
    	 JOptionPane.showMessageDialog(frm, "Hata="+ex.getMessage());//Bağlantıda hata olursa mesagebox' ta gösteriyoruz
     }
}
public void verigetir()
{    baglan();
    try {
    	Statement sorgu=baglanti.createStatement();//Yeni sorgu oluşturuyoruz
    	ResultSet veri=sorgu.executeQuery("select * from Kisiler");
        for(int i=0;i<dlm.length;i++)
        	dlm[i].clear();
            dlmyas.clear();
            dlmidler.clear();
    	while(veri.next())
    	{
    		dlm[0].addElement(veri.getString("Ad"));
    		dlm[1].addElement(veri.getString("SoyAd"));
    		dlmyas.addElement(veri.getInt("Yas"));
    		dlmidler.addElement(veri.getInt("KNO"));
    	}
    	veri.close();//Okuyucuyu kapatıyoruz
    	baglanti.close();//bağlantıyı kapatıyoruz
    }catch(Exception ex)
    {
    	JOptionPane.showMessageDialog(frm, "Hata="+ex.getMessage());
    }
}
public void ekle(JTextField[] jtxt,int yas)
{    baglan();//Veri tabanına bağlanıyoruz
   try {
	   PreparedStatement sorgu=baglanti.prepareStatement("insert into Kisiler(Ad,SoyAd,Yas) values(?,?,?)");
		sorgu.setString(1, jtxt[0].getText());//Paremetre ekliyoruz tip neyse ona göre
		sorgu.setString(2, jtxt[1].getText());
		sorgu.setInt(3, yas);
		sorgu.executeUpdate();
		baglanti.close();
   }catch(Exception ex)
   {
	   JOptionPane.showMessageDialog(frm, "Hata="+ex.getMessage()); 
   }
}
public void sil(DefaultListModel<String>[] dlmsil,int secilen)
{
	  baglan();//Veri tabanına bağlanıyoruz
	   try {
		  PreparedStatement sorgu=baglanti.prepareStatement("delete from Kisiler where Ad=? and SoyAd=?");
	      sorgu.setString(1,dlmsil[0].getElementAt(secilen));//Jlist secilen eleman silinecek
	      sorgu.setString(2,dlmsil[1].getElementAt(secilen));
	      sorgu.executeUpdate();//Sorguyu çalıştırıyoruz
	      baglanti.close();
	   }catch(Exception ex)
	   {
		   JOptionPane.showMessageDialog(frm, "Hata="+ex.getMessage()); 
	   }
}
public void guncelle(int secilen)
{      baglan();
	try {
		PreparedStatement sorgu=baglanti.prepareStatement("update Kisiler set Ad=?,SoyAd=?,Yas=? where KNO=?");
		sorgu.setString(1,jtext_gun[0].getText());
		sorgu.setString(2, jtext_gun[1].getText());
		sorgu.setInt(3, yas_gun);
		sorgu.setInt(4,dlmidler.getElementAt(secilen));
		sorgu.executeUpdate();
		baglanti.close();

	}catch(Exception ex)
	{
		JOptionPane.showMessageDialog(frm, "Hata="+ex.getMessage()); 
	}
}
}

 

Java KaloriHesaplahepsi indir

create database Kaloriler
create table Kategoriler(
KNO int primary key identity(10,10),
KAD nvarchar(50) not null
)
create table Besinler(
BNO int primary key identity(1,1),
BAD nvarchar(50) not null,
BM?KTAR float not null,
BKALOR? float not null,
KNO int not null
foreign key(KNO) references Kategoriler(KNO)
)
import java.io.*;
import java.sql.*;

public class Calistir {

	public Connection baglan()
	{   
		Connection baglanti=null;
		try
		{
			 baglanti=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=Kaloriler;integratedSecurity=true");
		}
		catch(SQLException ex)
		{
			System.out.println(ex.getMessage()+"hata");
		}
	return baglanti;}
	public int kategoriekle(String ad,String birim)
	{  int no=0;
		Connection baglanti=null;
		try
		{
			 baglanti=baglan();
			 PreparedStatement sorgu=baglanti.prepareStatement("insert into Kategoriler(KAD,KBİRİM) values(?,?)");
			 sorgu.setString(1, ad);
			 sorgu.setString(2, birim);
			 sorgu.executeUpdate();
		    baglanti.close(); 
		}
		catch(SQLException ex)
		{
			System.out.println(ex.getMessage());	
		}
	
	try {
			baglanti=baglan();
			PreparedStatement sorgu2=baglanti.prepareStatement("select KNO from Kategoriler where KAD=?");
			   sorgu2.setString(1,ad);
			   ResultSet veri=sorgu2.executeQuery();
			   veri.next();
			   no=veri.getInt("KNO");
			   veri.close();
			   baglanti.close();
		}
		catch(SQLException ex1)
		{
		System.out.println(ex1.getMessage());	
		}
	return no;}
	public void bekle(String ad,double miktar,double kalori,int kno)
	{
		Connection baglanti=null;
		try
		{
			 baglanti=baglan();
			 PreparedStatement sorgu=baglanti.prepareStatement("insert into Besinler(BAD,BMİKTAR,BKALORİ,KNO) values(?,?,?,?)");
			 sorgu.setString(1, ad);
			 sorgu.setDouble(2, miktar);
			 sorgu.setDouble(3,kalori);
			 sorgu.setInt(4, kno);
			 sorgu.executeUpdate();
		   baglanti.close();
		}
		catch(SQLException ex)
		{
			
		}	
	}
public static void main(String[] arg) throws FileNotFoundException 
{ 
String[] kategoriler= {"Sebzeler","Şarküteri","Et Ürünleri","Şekerli Gıdalar","Yağlar","Kuru Gıdalar","Unlu Mamuller","Meyveler","Süt Ürünleri","İçecekler","Çorbalar","Tatlılar"}; 
String yol="C:\\Users\\Ali\\Desktop\\Kalori.txt";
Calistir db=new Calistir();
try 
{
    File dosya=new File(yol);
	BufferedReader bfr=new BufferedReader(new FileReader(dosya));
int no=0;
	while(bfr.ready())
{  
    boolean durum=false;
	String[] veri=bfr.readLine().split(":");
    if(veri.length==2)
    {
    	String ad=veri[0].trim();
    	String miktar=veri[1].trim();
    	for(int i=0;i<kategoriler.length;i++)
    	{
    		if(ad.equals(kategoriler[i]))
    		{
    			durum=true;
    			break;
    		}			
    	}
    	if(durum)
            no=db.kategoriekle(ad,"100gr");
    	else 
    		 db.bekle(ad,100.0,Double.parseDouble(miktar), no);
    }
}
}
catch(IOException ex)
{
  	System.out.println(ex.getMessage());
}
}
}
package VeriTabani;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import com.microsoft.sqlserver.jdbc.*;

public class DB {

private Connection baglan() 
{
  Connection baglanti=null;
  try
  {   
	  baglanti=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=Kaloriler;integratedSecurity=true");
  }
	catch(SQLException ex)
  {
		JOptionPane.showMessageDialog(null, "HATA="+ex.getMessage());
  }
return baglanti;}

public void kategorigetir(JComboBox<String> jckategori,JComboBox<Integer> jcnumara)
{
   jckategori.removeAllItems();	
   jcnumara.removeAll();
   Connection baglanti=null;
   try
   {
 	  baglanti=baglan();
 	  Statement sorgu=baglanti.createStatement();
 	  ResultSet veri=sorgu.executeQuery("select KAD,KNO from Kategoriler");
      while(veri.next())
    	  {
    	       jckategori.addItem(veri.getString("KAD"));
    	       jcnumara.addItem(veri.getInt("KNO"));
    	  }
      jcnumara.setSelectedIndex(0);
      veri.close();
      baglanti.close();
   }
 	catch(SQLException ex)
   {   
 		JOptionPane.showMessageDialog(null, "HATA="+ex.getMessage());
   }

}
public void besinekle(String besinad,double besinmiktar,double kalori,int kno)
{
	   Connection baglanti=null;
	   try
	   {
	 	  baglanti=baglan();
	 	  PreparedStatement sorgu=baglanti.prepareStatement("insert into Besinler(BAD,BMİKTAR,BKALORİ,KNO) values(?,?,?,?)");
	 	  sorgu.setString(1, besinad);
          sorgu.setDouble(2, besinmiktar);
          sorgu.setDouble(3, kalori);
          sorgu.setInt(4, kno);  
          sorgu.executeUpdate();
          baglanti.close();
	   }
	 	catch(SQLException ex)
	   {   
	 		JOptionPane.showMessageDialog(null, "HATA="+ex.getMessage());
	   }
}
public void kategoriekle(String kad)
{
	 Connection baglanti=null;
	   try
	   {
	 	  baglanti=baglan();
	 	  PreparedStatement sorgu=baglanti.prepareStatement("insert into Kategoriler(KAD) values(?)");
	 	  sorgu.setString(1, kad);
          sorgu.executeUpdate();
          baglanti.close();
	   }
	 	catch(SQLException ex)
	   {   
	 		JOptionPane.showMessageDialog(null,"HATA="+ex.getMessage());
	   }
}
public void kategorisil(int KNO)
{
	 Connection baglanti=null;
	   try
	   {
	 	  baglanti=baglan();
	 	  PreparedStatement sorgu=baglanti.prepareStatement("delete from Besinler where KNO=? delete from Kategoriler where KNO=?");
	 	  sorgu.setInt(1,KNO);
	 	  sorgu.setInt(2, KNO);
        sorgu.executeUpdate();
        baglanti.close();
	   }
	 	catch(SQLException ex)
	   {   
	 		JOptionPane.showMessageDialog(null,"HATA="+ex.getMessage());
	   }
}
public void kategoriguncelle(String ad,int kno)
{
  Connection baglanti=null;
  try
  {
	  baglanti=baglan();
	  PreparedStatement sorgu=baglanti.prepareStatement("update Kategoriler set KAD=? where KNO=?");
	  sorgu.setString(1, ad);
	  sorgu.setInt(2, kno);
	  sorgu.executeUpdate();
	  baglanti.close();
	  
  }catch(SQLException ex)
  {
	  JOptionPane.showMessageDialog(null, ex.getMessage());
  }
}
public void listdoldur(DefaultListModel[] dlm,int kno,DefaultComboBoxModel[] dcm)
{
	 for(int i=0;i<dlm.length;i++)
	 { 
		 dlm[i].clear();
	     dcm[i].removeAllElements();
	 }
	 Connection baglanti=null;
	   try
	   {
	 	  baglanti=baglan();
	 	  PreparedStatement sorgu=baglanti.prepareStatement("select * from Besinler where KNO=?");
	 	  sorgu.setInt(1,kno);
         ResultSet veri=sorgu.executeQuery();
         while(veri.next())
         {
        	   dlm[0].addElement(veri.getString("BAD"));
        	   dlm[1].addElement(veri.getDouble("BMİKTAR"));
        	   dlm[2].addElement(veri.getDouble("BKALORİ"));
        	   dcm[0].addElement(veri.getString("BAD"));
        	   dcm[1].addElement(veri.getDouble("BMİKTAR"));
        	   dcm[2].addElement(veri.getDouble("BKALORİ"));   	  
         }
         veri.close();
         baglanti.close();
	   }
	 	catch(SQLException ex)
	   {   
	 		JOptionPane.showMessageDialog(null,"HATA="+ex.getMessage());
	   }
}
public void besinsil(String ad,int kno)
{
    Connection baglanti=null;
    try
    {
    	baglanti=baglan();
     	PreparedStatement sorgu=baglanti.prepareStatement("delete from Besinler where BAD=? and KNO=?");
        sorgu.setString(1, ad);
     	sorgu.setInt(2, kno);
     	sorgu.executeUpdate();
     	baglanti.close();
    }
    catch(SQLException ex)
    {
    	JOptionPane.showMessageDialog(null,"HATA="+ex.getMessage());
    }
}
public void besinguncelle(String ad,double miktar,double kalori,int kno,int bno)
{   
	Connection baglanti=null;
      try {
    	  baglanti=baglan();
          PreparedStatement sorgu=baglanti.prepareStatement("update Besinler set BAD=?,BMİKTAR=?,BKALORİ=? where KNO=? and BNO=?"); 
           sorgu.setString(1, ad);
           sorgu.setDouble(2, miktar);
           sorgu.setDouble(3, kalori);
           sorgu.setInt(4, kno);
           sorgu.setInt(5, bno);
          sorgu.executeUpdate();
      }  
      catch(SQLException ex)
      {
    	  JOptionPane.showMessageDialog(null,"HATA="+ex.getMessage());		  
      }
}
public int BNOBUL(String ad,int kno)
{   int bno=0;
   Connection baglanti=null;
    try {
    	baglanti=baglan();
    	PreparedStatement sorgu=baglanti.prepareStatement("select BNO from Besinler where BAD=? and KNO=?");
    	sorgu.setString(1, ad);
    	sorgu.setInt(2, kno);
        ResultSet veri=sorgu.executeQuery();
        veri.next();
        bno=veri.getInt("BNO");
        veri.close();
        baglanti.close();
    }catch(SQLException ex)
    {
    	JOptionPane.showMessageDialog(null,"HATA="+ex.getMessage());
    }
return bno;}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import VeriTabani.*;

class Kalori  implements ActionListener,ListSelectionListener,ItemListener{
	    DB dbislem;
	    JPanel anajpn,jpn[]=new JPanel[3];
	    JScrollPane[] jsc=new JScrollPane[3]; 
	    JList[] jlist=new JList[3];
	    DefaultListModel[] dlm=new DefaultListModel[3];
	    JLabel[] jlb=new JLabel[3];
	    String[] baslik= {"Besin","Miktar","Kalori"};
	    JTextField jtpor,jtext[]=new JTextField[3];
	    JButton[] jbtn=new JButton[4];
	    String[] btitle= {"Ekle","Sil","Düzenle","Cıkış"};
	    JComboBox<String> jcsecim; 
	    JComboBox<Integer> jcno; 
	    JFrame frm,frmgun;
	    JButton[] btnkategori; 
    public Kalori(JFrame frm1)
	{   dbislem=new DB();//Veri Tabanı işlemleri icin nesne tanımlanıyor
    	frm=frm1; 
		frm=new JFrame("Kalori Hesaplama");
		frm.setSize(500,500);
		frm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frm.setLayout(new FlowLayout());
		
		//Anapanel
		anajpn=new JPanel();
		anajpn.setPreferredSize(new Dimension(450,450));
		anajpn.setLayout(new FlowLayout());
		
		//
		    JPanel jpn_secim=new JPanel();
		    jpn_secim.setPreferredSize(new Dimension(100,450));
		    jcsecim=new JComboBox<String>();
		    jcsecim.setPreferredSize(new Dimension(100,20));
		    JLabel jlkategori=new JLabel("Kategoriler");
		    jlkategori.setPreferredSize(new Dimension(100,25));
		    jpn_secim.add(jlkategori);
		    jpn_secim.add(jcsecim);
		    btnkategori=new JButton[3];
		    for(int i=0;i<btnkategori.length;i++)
		    {
		    	btnkategori[i]=new JButton(btitle[i]);
		    	btnkategori[i].setPreferredSize(new Dimension(100,20));
		    	btnkategori[i].addActionListener(this);
		    	btnkategori[i].setActionCommand("btn_"+btitle[i]);
		    	jpn_secim.add(btnkategori[i]);
		    }
		    jcno=new JComboBox<Integer>();
		    jcno.setPreferredSize(new Dimension(100,22));
			dbislem.kategorigetir(jcsecim,jcno);
			jcno.setSelectedIndex(0);
			jcsecim.addItemListener(this);
		anajpn.add(jpn_secim);
		for(int i=0;i<jlist.length;i++)
		{
			jpn[i]=new JPanel();
			jpn[i].setPreferredSize(new Dimension(100,450));
			jpn[i].setLayout(new FlowLayout());
	
			jlb[i]=new JLabel(baslik[i]);
			jlb[i].setPreferredSize(new Dimension(100,22));
		     
			jtext[i]=new JTextField();
			jtext[i].setPreferredSize(new Dimension(100,22));	
		    
			dlm[i]=new DefaultListModel();
		    jlist[i]=new JList(dlm[i]);
		    jlist[i].addListSelectionListener(this);
		    jsc[i]=new JScrollPane(jlist[i]);
		    jsc[i].setPreferredSize(new Dimension(100,290));
	        
		    jbtn[i]=new JButton(btitle[i]);	    
		    jbtn[i].setPreferredSize(new Dimension(100,22));
		    jbtn[i].addActionListener(this);
		    jbtn[i].setActionCommand(btitle[i]);
		   
		    jpn[i].add(jlb[i]);
		    jpn[i].add(jsc[i]);
		    jpn[i].add(jtext[i]);
		    jpn[i].add(jbtn[i]);
		    anajpn.add(jpn[i]);
		}
		for(int i=0;i<Calistir.jcombo[0].getItemCount();i++)
		{
		    dlm[0].addElement(Calistir.dcm[0].getElementAt(i));
			double miktar=sayicevir(Calistir.dcm[1].getElementAt(i).toString());
			double kalori=sayicevir(Calistir.dcm[2].getElementAt(i).toString());
		}
		
		dbislem.listdoldur(dlm,jcno.getItemAt(jcno.getSelectedIndex()),Calistir.dcm);
		jbtn[3]=new JButton(btitle[3]);
		jbtn[3].setPreferredSize(new Dimension(100,22));
		jbtn[3].addActionListener(this);
		jbtn[3].setActionCommand(btitle[3]);
		jpn[0].add(jbtn[3]);
        frm.add(anajpn); 
		frm.setVisible(true);
	}
    JPanel gun[],anagun;
    JTextField[] tgun;
    JLabel[] jlgun;
    String[] jlisim= {"Besin Ad:","Miktarı:","Kalorisi:"};
    JButton btngun;
    public void guncelle()
    {  
    	frmgun=new JFrame("Düzenle");
    	frmgun.setSize(300, 250);
    	frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frm.setLayout(new FlowLayout());
    	anagun=new JPanel();
        anagun.setPreferredSize(new Dimension(225,150));
    	gun=new JPanel[2];
    	tgun=new JTextField[3];
    	jlgun=new JLabel[3];
    	btngun=new JButton("Güncelle");
    	btngun.setPreferredSize(new Dimension(100,20));
    	btngun.addActionListener(this);
    	btngun.setActionCommand("Duzenle");
    	for(int i=0;i<gun.length;i++)
    	{
     	   gun[i]=new JPanel();
     	   gun[i].setPreferredSize(new Dimension(100,100));	
    	}
       for(int i=0;i<tgun.length;i++)
       {
    	   tgun[i]=new JTextField();
    	   tgun[i].setPreferredSize(new Dimension(100,20));
    	   jlgun[i]=new JLabel(jlisim[i]);
    	   jlgun[i].setPreferredSize(new Dimension(100,20));
    	   jlgun[i].setHorizontalAlignment(JLabel.RIGHT);
           gun[0].add(jlgun[i]);
           gun[1].add(tgun[i]);
       }
           gun[1].add(btngun);
          anagun.add(gun[0]);
          anagun.add(gun[1]);
    frmgun.add(anagun);
    frmgun.setVisible(true);
    } 
	public static boolean dogrula(JTextField[] jtext)
	{
		int boyut=jtext.length;
	    int sayac=0;
	    for(int i=0;i<boyut;i++)
	        if(jtext[i].getText().length()>0)
	                sayac++;
	      if(sayac==boyut)
	    	   return true;
	return false;} 
   public static double sayicevir(String s)
   {
	   double sayi=-1;
	   try {
		   sayi=Double.parseDouble(s);
	      return sayi;
	   }
	   catch(Exception ex)
	   {
		   return sayi;
	   }
   }
   int BNO;
	@Override
	public void actionPerformed(ActionEvent arg0) {
		int secilen=jlist[0].getSelectedIndex();
		int secilen2=jcsecim.getSelectedIndex();
		double miktar=sayicevir(jtext[1].getText());
		double kalori=sayicevir(jtext[2].getText());
		if(arg0.getActionCommand().equals("Ekle")&&dogrula(jtext)&&miktar>0&&kalori>0&&secilen2>-1)
		{     dbislem.besinekle(jtext[0].getText(),miktar, kalori,jcno.getItemAt(secilen2));
			  dlm[0].addElement(jtext[0].getText());
			  dlm[1].addElement(miktar);
			  dlm[2].addElement(kalori);
			  Calistir.dcm[0].addElement(jtext[0].getText());   
			  Calistir.dcm[1].addElement(miktar);   
			  Calistir.dcm[2].addElement(kalori);   
			  for(int i=0;i<dlm.length;i++)
			    jtext[i].setText("");     
		}
		else if(arg0.getActionCommand().equals("Sil")&&secilen>-1&&secilen2>-1)
		{
			dbislem.besinsil(dlm[0].getElementAt(secilen).toString(),jcno.getItemAt(secilen2));
			for(int i=0;i<dlm.length;i++)
				{
				  dlm[i].removeElementAt(secilen);
		           Calistir.dcm[i].removeElementAt(secilen);
				}
		} 
		else if(arg0.getActionCommand().equals("Düzenle")&&secilen>-1)
		{   guncelle();
			for(int i=0;i<tgun.length;i++)
			{
				tgun[i].setText((dlm[i].getElementAt(secilen).toString()));
			}
			BNO=dbislem.BNOBUL(tgun[0].getText(), jcno.getItemAt(secilen2));
		}
		else if(arg0.getActionCommand().equals("Duzenle")&&dogrula(tgun))
		{
			int kno= jcno.getItemAt(secilen2);
	dbislem.besinguncelle(tgun[0].getText(), Double.parseDouble(tgun[1].getText()), Double.parseDouble(tgun[2].getText()),kno,BNO);
	for(int i=0;i<dlm.length;i++)
			    dlm[i].remove(secilen);
               double kamiktar=sayicevir(tgun[1].getText());
               double bkalori=sayicevir(tgun[2].getText());
        	   dlm[0].insertElementAt(tgun[0].getText(), secilen);
        	   dlm[1].insertElementAt(kamiktar, secilen);
        	   dlm[2].insertElementAt(bkalori, secilen);	
		     frmgun.dispose();
		}
		else if(arg0.getActionCommand().equals("Cıkış"))
		{
			frm.dispose();
			Calistir.frm1.setVisible(true);
		}
		else if(arg0.getActionCommand().equals("btn_Ekle"))
		{
			  String kategoriad=JOptionPane.showInputDialog(frm, "Yeni Kategori Adını Giriniz!!","",JOptionPane.YES_OPTION);	
			  if(kategoriad.length()>0)
					 {
						dbislem.kategoriekle(kategoriad);
						jcsecim.addItem(kategoriad);
					 }
		}
		else if(arg0.getActionCommand().equals("btn_Sil")&&secilen2>-1)
		{
	      int durum=JOptionPane.showConfirmDialog(frm, "Bu kategori silerseniz Bu kategoriye ait Besinleride silersiniz!!");
		    if(durum==0)
	       {
		    	dbislem.kategorisil(jcno.getItemAt(secilen2));
		    	dbislem.kategorigetir(jcsecim,jcno);
	       }
	       }
		else if(arg0.getActionCommand().equals("btn_Düzenle")&&secilen2>-1)
		{
			String kategoriad=JOptionPane.showInputDialog(frm, "Kategorinin İsmini Düzenleyin","",JOptionPane.YES_OPTION);	
			  if(kategoriad.length()>0)
					 {  int kno=jcno.getItemAt(secilen2);
						dbislem.kategoriguncelle(kategoriad, kno);					
						dbislem.kategorigetir(jcsecim,jcno);
					 }
		}
		else
			JOptionPane.showMessageDialog(frm, "Alanlar Boş gecilemez");
	}
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
	     JList jlb=(JList)arg0.getSource();
	 int  secilen=jlb.getSelectedIndex();
		   for(int i=0;i<jlist.length;i++)
		       jlist[i].setSelectedIndex(secilen);
	}
	@Override
	public void itemStateChanged(ItemEvent arg0) {
		JComboBox<Integer> jcombo=(JComboBox<Integer>)arg0.getSource();
		if(arg0.getStateChange()==ItemEvent.SELECTED)
     	   	dbislem.listdoldur(dlm,jcno.getItemAt(jcombo.getSelectedIndex()),Calistir.dcm);
		   }           
}
/////////////////////////////
public class Calistir implements ActionListener,ListSelectionListener {
    JPanel anajpn,jpn[]=new JPanel[4];
    JScrollPane[] jsc=new JScrollPane[3]; 
    JList[] jlist=new JList[3];
    DefaultListModel[] dlm=new DefaultListModel[3];
    JLabel[] jlb=new JLabel[3];
    String[] baslik= {"Kilo:","Boy:","Yaş:"};
    JLabel[] jlad=new JLabel[3];
    String[] jisim= {"Besinler","Porsiyon","Kalorisi"};
    JTextField jtpor,jtext[]=new JTextField[3];
    JButton[] jbtn=new JButton[3];
    String[] btitle= {"Ekle","Sil","Kalori"};
   static JComboBox[] jcombo=new JComboBox[3];
   static DefaultComboBoxModel[] dcm=new DefaultComboBoxModel[3];
	JLabel[] jlb1=new JLabel[2];
	String[] baslik1= {"Günlük kalori:","Toplam Kalori:"};
	JRadioButton[] jrd=new JRadioButton[2];
	String[] cins= {"Erkek","Kız"};
	ButtonGroup grup=new ButtonGroup();
	static JFrame frm1;
	static JFrame frm2;
    public Calistir()
	{
		frm1=new JFrame("Kalor Hesaplama");
		frm1.setSize(500,500);
		frm1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frm1.setLayout(new FlowLayout());
		
		//Anapanel
		anajpn=new JPanel();
		anajpn.setPreferredSize(new Dimension(400,500));
		anajpn.setLayout(new FlowLayout());
		
		//
		for(int i=0;i<jlist.length;i++)
		{
			jpn[i]=new JPanel();
			jpn[i].setPreferredSize(new Dimension(100,500));
			jpn[i].setLayout(new FlowLayout());
			jlb[i]=new JLabel(baslik[i]);
			jlb[i].setPreferredSize(new Dimension(25,25));
			jlad[i]=new JLabel(jisim[i]);
			jlad[i].setPreferredSize(new Dimension(100,18));
			jtext[i]=new JTextField();
			jtext[i].setPreferredSize(new Dimension(65,25));	
			jtext[i].setText("10");
			dlm[i]=new DefaultListModel();
		    jlist[i]=new JList(dlm[i]);
		    jlist[i].addListSelectionListener(this);
		    jsc[i]=new JScrollPane(jlist[i]);
		    jsc[i].setPreferredSize(new Dimension(100,290));
		    jpn[i].add(jlb[i]);
		    jpn[i].add(jtext[i]);
		    jpn[i].add(jlad[i]);
		    jpn[i].add(jsc[i]);
		    anajpn.add(jpn[i]);
		    dcm[i]=new DefaultComboBoxModel();
		}
		jcombo[0]=new JComboBox(dcm[0]);
		jcombo[0].setPreferredSize(new Dimension(100,25));
		jtpor=new JTextField();
		jtpor.setPreferredSize(new Dimension(100,25));
		jpn[0].add(jcombo[0]);
		jpn[1].add(jtpor);
		for(int i=0;i<jlb1.length;i++)
		{    
			jlb1[i]=new JLabel(baslik1[i]);
			jlb1[i].setPreferredSize(new Dimension(90,10));
			jpn[2].add(jlb1[i]);
	  		jcombo[i+1]=new JComboBox(dcm[i+1]);
		}
		for(int i=0;i<jbtn.length;i++)
		{
			jbtn[i]=new JButton(btitle[i]);	    
		    jbtn[i].setPreferredSize(new Dimension(100,25));
		    jbtn[i].addActionListener(this);
		    jbtn[i].setActionCommand(btitle[i]);
		    jpn[i].add(jbtn[i]);
		    anajpn.add(jpn[i]);
		}
		
		jpn[3]=new JPanel();
		jpn[3].setPreferredSize(new Dimension(70,407));
		jrd[0]=new JRadioButton(cins[0],true);
		jrd[0].setPreferredSize(new Dimension(70,25));
		jrd[1]=new JRadioButton(cins[1],false);
		jrd[1].setPreferredSize(new Dimension(70,25));
		grup.add(jrd[0]);
		grup.add(jrd[1]);
		jpn[3].add(jrd[0]);
		jpn[3].add(jrd[1]);
		anajpn.add(jpn[3]);
		frm1.add(anajpn);
		frm1.setVisible(true);
	}
    @Override
    public void actionPerformed(ActionEvent arg)
    {
    	 int secilen1=jcombo[0].getSelectedIndex();
    	 double por=Kalori.sayicevir(jtpor.getText());
    	 int secilen2=jlist[0].getSelectedIndex();
    	if(arg.getActionCommand().equals("Ekle")&&secilen1>-1&&por>0)
    	{
    		dlm[0].addElement(dcm[0].getElementAt(secilen1));
    		dlm[1].addElement(virgul(por));
    		double kalori=(por*(double)dcm[2].getElementAt(secilen1))/(double)dcm[1].getElementAt(secilen1);
    	    dlm[2].addElement(virgul(kalori));
    	    gunkal();
    	    topkal();
    	    jtpor.setText("");
    	}
    	else if(arg.getActionCommand().equals("Sil")&&secilen2>-1)
    	{
    		for(int i=0;i<dlm.length;i++)
    			dlm[i].removeElementAt(secilen2);
    		  topkal();
    	}
    	else if(arg.getActionCommand().equals("Kalori"))
    		{   frm1.setVisible(false);
    		   new Kalori(frm2);  	
    		}
    	else
    		JOptionPane.showMessageDialog(frm1,"Besin secilmek zorunda ve miktar boş gecilemez");
    }
    private void topkal()
    {
    	double toplam=0;
    	for(int i=0;i<dlm[2].getSize();i++)
    		toplam+=(double)dlm[2].getElementAt(i);
    	jlb1[1].setText("Top Kal:"+virgul(toplam));
    }
    public static double virgul(double sayi)
    {
    	double sonuc=sayi*100;
    	int sonuc1=(int)sonuc;		
    	sonuc=sonuc1/100.0;
    return sonuc;}
    
    public void gunkal()
    {  double[] erkek= {66,13.7,5,6.8};
       double[] kadin= {655,9.6,1.8,4.7};
       double sonuc=0.0;
      double[] oranlar=kadin;
      double[] degerler=new double[4];
      degerler[0]=1;
      for(int i=0;i<jtext.length;i++)
    	  degerler[i+1]=Kalori.sayicevir(jtext[i].getText());
      
      if(jrd[0].isSelected())//jrd radiobuuton secilimi değilmi
    	  oranlar=erkek;
      if(Kalori.dogrula(jtext))
        sonuc=(oranlar[0]*degerler[0]+oranlar[1]*degerler[1]+oranlar[2]*degerler[2])-(oranlar[3]*degerler[3]);
    jlb1[0].setText("Gün Kal:"+sonuc); 
    }
	public static void main(String[] arg)
	{
    new Calistir();
	}
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
	     JList jlb=(JList)arg0.getSource();
	     int secilen=jlb.getSelectedIndex();  
	   if(secilen>-1)
	   {
		   for(int i=0;i<jlist.length;i++)
		       jlist[i].setSelectedIndex(secilen);
	   }
	}  
}