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()); 
	}
}
}

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Calistir implements KeyListener {
      JFrame frm;
      JTextField jtext;
      JPanel jpn;
      JLabel jlb;
	public Calistir()
	{
		frm=new JFrame("Form");
		frm.setSize(300,300);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frm.setLayout(new FlowLayout());
		
		jpn=new JPanel();
		jpn.setPreferredSize(new Dimension(100,100));
		jpn.setLayout(new FlowLayout());
		
		jtext=new JTextField();
		jtext.setPreferredSize(new Dimension(100,25));
		jtext.addKeyListener(this);
		
		jlb=new JLabel("===");
		jlb.setPreferredSize(new Dimension(100,25));

		jpn.add(jtext);
		jpn.add(jlb);
		frm.add(jpn);
		frm.setVisible(true);
	}
	public static void main(String[] arg)
	{
		new Calistir();
	}
	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
	//	JTextField txt=(JTextField)arg0.getSource();
	//	jlb.setText(txt.getText());
		//Birden fazla karekter girilirken Bu fonksiyon çalısıyor.
	}
	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		JTextField txt=(JTextField)arg0.getSource();
		jlb.setText(txt.getText());
	//İçine karekter girildiği anda bu fonksiyon çalıştırılıyor.
	}
	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}

 

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);
	   }
	}  
}

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calistir implements ItemListener{
    JFrame frm;
    JRadioButton[] jrd;
    ButtonGroup btng;//Tek Butonun secilmesi icin 
    JPanel jpn;
	public Calistir()
	{
		frm=new JFrame("Form");
		frm.setSize(500,400);
	    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frm.setLayout(new FlowLayout());
	    
	    jrd=new JRadioButton[8];
	    btng=new ButtonGroup();
	    jpn=new JPanel();
	    jpn.setPreferredSize(new Dimension(500,400));
	    jpn.setLayout(new FlowLayout());
	    for(int i=0;i<8;i++)
	    {   
	    	jrd[i]=new JRadioButton(i+1+")"+"R-Buton");
	    	jrd[i].setPreferredSize(new Dimension(100,25));
	    	jrd[i].addItemListener(this);//JRbutton Dinleyici
	        btng.add(jrd[i]);
	        jpn.add(jrd[i]);
	    }
	    jrd[0].setSelected(true);
	    frm.add(jpn);
	    frm.setVisible(true);
	}
	public void itemStateChanged(ItemEvent e)//JR Button dinleyici fonk tıklandıgında bu fonk calisir
	{    JRadioButton jb=(JRadioButton)e.getSource();//Hangi JR buton tıklandı
		 frm.setTitle(jb.getText());//hangi JRbutton tıklanıldıysa onun texti formun title 'i oluyor
	}
	public static void main(String[] arg)
	{
		new Calistir();
	}
}

 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Tasarim implements ActionListener {
   JList[] lbox=new JList[4];
   DefaultListModel[] dlm=new DefaultListModel[4]; 
   JTextField[] tbox=new JTextField[3];
   JTextField[] tbox1=new JTextField[3];
	JButton[] buton=new JButton[4];
	JComboBox csehir,csehir2;
	JPanel anajpn,gunjpn,jpn[]=new JPanel[6];
	JScrollPane[] scp=new JScrollPane[4];
	String[] btitle= {"Ekle","Sil","Güncelle"};
	DefaultComboBoxModel dcmsehir=new DefaultComboBoxModel();
	DefaultComboBoxModel dcmsehir2=new DefaultComboBoxModel();
	JLabel[] jlb=new JLabel[4]; 
	JLabel[] jlb2=new JLabel[4]; 
	String[] baslik= {"AD","SOYAD","YAŞ","ŞEHİR"}; 
	String[] sehirler= {"K.Maraş","Osmaniye","Hatay","Gaziantep","Malatya","Mersin"};
	JFrame frm,frm2;
   public Tasarim()
	{
	    frm=new JFrame("Baslik");
		frm.setSize(600, 600);
		frm.setLayout(new FlowLayout());
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
		anajpn=new JPanel();
		anajpn.setPreferredSize(new Dimension(400,500));
		anajpn.setLayout(new GridLayout(1,4));
	  for(int i=0;i<tbox.length;i++)
	  {
		  jpn[i]=new JPanel();
		  dlm[i]=new DefaultListModel();
		  lbox[i]=new JList(dlm[i]);
		  scp[i]=new JScrollPane(lbox[i]);
		  scp[i].setPreferredSize(new Dimension(100,300));
		  tbox[i]=new JTextField();
		  tbox[i].setPreferredSize(new Dimension(100,25));
		  buton[i]=new JButton(btitle[i]);
		  buton[i].setPreferredSize(new Dimension(100,25));
		  buton[i].addActionListener(this);
		  buton[i].setActionCommand(btitle[i]);
		  jlb[i]=new JLabel(baslik[i]);
		  jpn[i].add(jlb[i]);
		  jpn[i].add(scp[i]);
		  jpn[i].add(tbox[i]);
		  jpn[i].add(buton[i]);
	      anajpn.add(jpn[i]);
		if(i==tbox.length-1)
		{
			  jpn[i+1]=new JPanel();
			  dlm[i+1]=new DefaultListModel();
			  lbox[i+1]=new JList(dlm[i+1]);
			  scp[i+1]=new JScrollPane(lbox[i+1]);
			  scp[i+1].setPreferredSize(new Dimension(100,300));
			  csehir=new JComboBox(dcmsehir);
			  csehir.setPreferredSize(new Dimension(100,25));
			  jlb[i+1]=new JLabel(baslik[i+1]);
			  jpn[i+1].add(jlb[i+1]);
			  jpn[i+1].add(scp[i+1]);
			  jpn[i+1].add(csehir);
		      anajpn.add(jpn[i+1]);
			break;
		}
	     
	  }
	  csehir2=new JComboBox(dcmsehir2);
	  csehir2.setPreferredSize(new Dimension(100,25));
	  for(int i=0;i<sehirler.length;i++)
	  {
		  dcmsehir.addElement(sehirler[i]);
		  dcmsehir2.addElement(sehirler[i]);
	  } 
	     frm.add(anajpn);
	     frm.setVisible(true);
	   
	}
   private void gungoster(String[] txtler)
   {
	     frm2=new JFrame("Güncelle");
	    frm2.setSize(300, 300);
	    frm2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frm2.setLayout(new FlowLayout());
		  //Güncelleme
		  gunjpn=new JPanel();
		  gunjpn.setPreferredSize(new Dimension(200,170));
		  gunjpn.setLayout(new FlowLayout());
		  jpn[4]=new JPanel();
		  jpn[4].setPreferredSize(new Dimension(75,150));
		  jpn[5]=new JPanel();
		  jpn[5].setPreferredSize(new Dimension(100,150));
		  for(int i=0;i<tbox1.length;i++)
		  {     tbox1[i]=new JTextField();
		        tbox1[i].setPreferredSize(new Dimension(100,25));
		        tbox1[i].setText(txtler[i]);
			    jlb2[i]=new JLabel(baslik[i]);
		        jlb2[i].setPreferredSize(new Dimension(50,25));
			    jpn[4].add(jlb2[i]);
			    jpn[5].add(tbox1[i]);
		  }
		  
		  jlb2[3]=new JLabel(baslik[3]);
		  jlb2[3].setPreferredSize(new Dimension(50,25));
		  buton[3]=new JButton("Güncelle");
		  buton[3].setPreferredSize(new Dimension(100,25));
		  buton[3].setActionCommand("gun");
		  buton[3].addActionListener(this);
		  jpn[4].add(jlb2[3]);
		   jpn[5].add(csehir2);
		   jpn[5].add(buton[3]);
		  gunjpn.add(jpn[4]);
		  gunjpn.add(jpn[5]);
	     frm2.add(gunjpn);
	     frm2.setVisible(true);
   }
   //Override
   public void actionPerformed(ActionEvent arg)
   {    int yas=sayicevir(tbox[2].getText());
	    int secilen=csehir.getSelectedIndex();
	    int secilen2=lbox[0].getSelectedIndex();
	    int secilen3=csehir2.getSelectedIndex();
	   boolean durum=dogrula(tbox);
	    if(arg.getActionCommand()=="Ekle"&&yas!=-1)
	    {
	    	dlm[0].addElement(tbox[0].getText());
	    	dlm[1].addElement(tbox[1].getText());
	    	dlm[2].addElement(tbox[2].getText());
	    	dlm[3].addElement(dcmsehir.getElementAt(secilen));
	    	for(int i=0;i<tbox.length;i++)
	    		tbox[i].setText("");
	    }
	    if(arg.getActionCommand()=="Sil"&&secilen2>-1)
	    {
	    	 for(int i=0;i<lbox.length;i++)
                 dlm[i].removeElementAt(secilen2);
	    }
	    if(arg.getActionCommand()=="Güncelle"&&secilen2>-1)
	    {   String[] txtler=new String[3]; 
	        for(int i=0;i<txtler.length;i++)
	        	  txtler[i]=(String)dlm[i].getElementAt(secilen2);
	    	 frm.setVisible(false);
	    	 gungoster(txtler);
	    	 
	    }
        if(arg.getActionCommand()=="gun"&&secilen3>-1)
        {   if(dogrula(tbox1)) {
        	 for(int i=0;i<lbox.length;i++)
                 dlm[i].removeElementAt(secilen2);
         for(int i=0;i<tbox1.length;i++)
            dlm[i].insertElementAt(tbox1[i].getText(), secilen2);
            dlm[3].insertElementAt(dcmsehir2.getElementAt(secilen3), secilen2);
        	frm2.setVisible(false);
        	frm.setVisible(true);
        }
        }
   }
   private boolean dogrula(JTextField[] txt)
   {
	    int sayac=0;
	    for(int i=0;i<txt.length;i++)
	    	if(txt[i].getText().length()>0)
	    		sayac++;
         if(txt.length==sayac)
        	 return true;
         else
        	 return false;
   }
   private int sayicevir(String yas)
   {
	   int sayi=-1;
	   try {
		   sayi=Integer.parseInt(yas);
		   return sayi;
	   }catch(Exception ex)
	   {
		   sayi=-1;
		   return sayi;
	   }
   }
	public static void main(String[] arg)
	{
		new Tasarim();
	}
}

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class buton1 implements ActionListener{
	
	@Override
	public void actionPerformed(ActionEvent arg)
	{
		Calistir.jlb.setText("buton1");	
	}
}
class buton2  implements ActionListener{
   
	@Override
	public void actionPerformed(ActionEvent arg)
	{
		Calistir.jlb.setText("buton2");
	}
}
public class Calistir implements ActionListener {
  static JLabel jlb=new JLabel("----");
  JButton[] jbtn=new JButton[2];
  
	public Calistir()
	{
		JFrame frm=new JFrame("Form");
		frm.setSize(300,300);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frm.setLayout(new FlowLayout());
		
		jlb.setPreferredSize(new Dimension(100,25));
	    JPanel jpn=new JPanel();
	   jpn.setPreferredSize(new Dimension(100,100));
	  
	   for(int i=0;i<jbtn.length;i++)
	   {
		   jbtn[i]=new JButton("Buton"+(i+1));
		   jbtn[i].setPreferredSize(new Dimension(100,25)); 
	       jpn.add(jbtn[i]);
	   }
	  // jbtn[0].addActionListener(new buton1());// buton1 sınıfındaki actionPerformed fonksiyonun cağır
	   //jbtn[1].addActionListener(new buton2());// buton2 sınıfındaki actionPerformed fonksiyonun cağır
	   jbtn[0].addActionListener(this);//Bu sınıfta ki actionPerformed fonksiyonun cağır
	   jbtn[1].addActionListener(this);//Bu sınıfta ki actionPerformed fonksiyonun cağır
	   jbtn[0].setActionCommand("btn1");
	   jbtn[1].setActionCommand("btn2");
	   jpn.add(jlb);
	   frm.add(jpn);
	   frm.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent arg)
	{
		switch(arg.getActionCommand())
		{
		case "btn1":jlb.setText("buton1");break;
		case "btn2":jlb.setText("buton2");break;
		}
		
	}
	public static void main(String[] arg)
	{
		new Calistir();
	}
}

 

package Hesapla;
public class Hesapla {
public double fin,viz;
public double ort;

public boolean notgir(String pfin,String pviz)
{ double tfin=cevir(pfin),tviz=cevir(pviz);
	if(tfin!=-1&&tviz!=-1)
	{
		fin=tfin;
		viz=tviz;
		nothesapla();
	 return true;
	}
	else
		return false;
}


private double cevir(String not)
{
   double sonuc=0.0;
   try
   {
	sonuc=Double.parseDouble(not);   
     return sonuc; 
   }
   catch(Exception ex)
   {
	   return -1;
	   
   }
}
private void nothesapla()
{
ort=fin*0.6+viz*0.4;
int ort2=(int)(ort*100);
ort=ort2/100.0;
}

}
package main;
import Hesapla.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main implements ActionListener{
    JButton bsil,bekle;
    JList lvize,lfinal,lort;
    DefaultListModel  dlmvize,dlmfinal,dlmort;
    JTextField tvize,tfinal;
    JLabel jlvize,jlfinal,jlort,jlgenel;
	public Main()
	{
		JFrame frm=new JFrame("Hesaplama");
		frm.setSize(600, 600);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//kapanma kutusuna tıkladığımda programın sonlandırılması için
		frm.setLayout(new FlowLayout());//Componentlerin formda nasıl yerleseceği
        
		jlvize=new JLabel("Vize Notu");
		jlvize.setPreferredSize(new Dimension(150,25));
		jlfinal=new JLabel("Final Notu");
		jlfinal.setPreferredSize(new Dimension(150,25));
		jlort=new JLabel("Dersin Ortalaması");
		jlort.setPreferredSize(new Dimension(150,25));
		jlgenel=new JLabel("Genel Ortalama:");
		jlgenel.setPreferredSize(new Dimension(150,25));
		
		//Button
		bsil=new JButton("Sil");
		bsil.setPreferredSize(new Dimension(150,25));
		bsil.addActionListener(this);
		bsil.setActionCommand("sil");
		
		bekle=new JButton("Ekle");
		bekle.setPreferredSize(new Dimension(150,25));
		bekle.addActionListener(this);//Buton dinleyicisi bu sinifdaki  fonksiyonu(actionPerformed) calistir
		bekle.setActionCommand("ekle");//Butona komut ekliyorum ayırt edebilmek için
		
		//JTextField
		tvize=new JTextField();
		tvize.setPreferredSize(new Dimension(150,25));
		tfinal=new JTextField();
		tfinal.setPreferredSize(new Dimension(150,25));
		
		//DefaultListModel
	dlmvize=new DefaultListModel();
	dlmfinal=new DefaultListModel();
	dlmort=new DefaultListModel();
		
		//JListler
	   lvize=new JList(dlmvize);
	   lfinal=new JList(dlmfinal);
	   lort=new JList(dlmort);
		
	   //JScrollPane	  
	   JScrollPane spvize=new JScrollPane(lvize);//Kaydırma çubuğunun çıkması için
	   spvize.setPreferredSize(new Dimension(150,300));
	   JScrollPane spfinal=new JScrollPane(lfinal);
	   spfinal.setPreferredSize(new Dimension(150,300));
	   JScrollPane sport=new JScrollPane(lort);
	   sport.setPreferredSize(new Dimension(150,300));
	   
	   //Panel
	   
	   JPanel anajpn=new JPanel();
	   anajpn.setLayout(new GridLayout(1,3));
	   anajpn.setPreferredSize(new Dimension(450,500));
	   JPanel jpn1=new JPanel();
	   JPanel jpn2=new JPanel();
	   JPanel jpn3=new JPanel();
	  
	   jpn1.add(jlvize);
	   jpn1.add(spvize);
	   jpn1.add(tvize);
	   jpn1.add(bekle);
	   
	   jpn2.add(jlfinal);
	   jpn2.add(spfinal);
	   jpn2.add(tfinal);
	   jpn2.add(bsil);
	  
	   jpn3.add(jlort);
	   jpn3.add(sport);
	   jpn3.add(jlgenel);
	
	   
	   anajpn.add(jpn1);
	   anajpn.add(jpn2);
	   anajpn.add(jpn3);
	   
	  frm.add(anajpn);
	   frm.setVisible(true);
	}
	private void toplamort()
	{
		double genort=0;
		int boyut=dlmort.size();
		for(int i=0;i<boyut;i++)
		{
			try
			{ 
				genort+=Double.parseDouble(dlmort.getElementAt(i)+"");
			}catch(Exception ex)
			{
				
			}
			
		}
		genort/=boyut;
		boyut=(int)(genort*100);
		genort=boyut/100.0; 
		jlgenel.setText("Genel ortalama="+genort);
	}
	
	
	@Override
	public void actionPerformed(ActionEvent arg0) { //Butonlara tıklandıgında bu fonksiyon çalısır
		Hesapla ogr=new Hesapla();
		boolean k=ogr.notgir(tfinal.getText(), tvize.getText());
		int secilen=lvize.getSelectedIndex();
		if(arg0.getActionCommand().equals("ekle")&&k)
	{
			dlmvize.addElement(ogr.viz);
		    dlmfinal.addElement(ogr.fin);
		    dlmort.addElement(ogr.ort);
		    tvize.setText("");
		    tfinal.setText("");
		    toplamort();
	}
		 if(arg0.getActionCommand().equals("sil")&&secilen>-1)
		{
		  dlmvize.remove(secilen);
		  dlmfinal.remove(secilen);
		  dlmort.remove(secilen);
			toplamort();
		}
		
	}
	
	
	public static void main(String[] arg)
{
	new Main();

}

}

 

package Belirtec;

public class Erisim {

	int frienddegisken;
	public int publicdegisken;
	private int privatedegisken;
	protected int protecdegisken;
}
import Belirtec.*;
class Sinif{
	int frienddegisken;
    public int publicdegisken;
	private int privatedegisken;
	protected int protecdegisken;
}
public class ErisimBelirteci extends Erisim{
	int frienddegisken;
    public int publicdegisken;
	private int privatedegisken;
	protected int protecdegisken;
	public static void main(String[] arg)
	{
		ErisimBelirteci n1=new ErisimBelirteci();
        //n1. Dediğimizde Aynı sınıfta olduğumuz icin hepsini kullanabiliriz
	   Erisim n2=new Erisim();
	     //n2 dediğimiz zaman sadece public degiskeni kullanabiliriz
	     //farklı paketler friend,private,protected(kalıtım yapmadıgımız sürece)
	     // kullanamayız  
	     //Eğer Erisim sınıfını bu sınıfa extends edersek Farkli paketler 
	     //oldugu icin friend,private kullanmayız sadece public,protected(kalıtım yapıldığı icin) 
	     //kullanabiliriz
	     
	     Sinif n3=new Sinif();
	     //n3. dediğimiz zaman sadece private kullanılamaz diğer hepsi kullanılabilir
	}
}

 

import java.util.Scanner;
abstract class ortak{
	abstract void denkcoz();
	public void yazdir(String metin)
	{
	   System.out.println(metin);
	}
   
	public void yazdirprint(String metin)
   {
	   System.out.print(metin);
   }
   
   double sayial(String metin)
  {
	   double sayi=0;
	 boolean durum=true;
  while(durum)  
  {   yazdirprint(metin);
	  Scanner input=new Scanner(System.in);
	  try
	  { String s1=input.next();
		 sayi=Double.parseDouble(s1);
	     durum=false;
	  }catch(Exception ex)
	  {
		 yazdir("Hata tekrar girin");
		  durum=true;
	  }
  }
 return sayi; }	
}
class derece1 extends ortak{
	String[] isim={"a","b","c"}; 
    double[] deger=new double[3];
	public derece1()
	{  
		denkcoz();
	}
	
	void denkcoz()
	{
		yazdir("Denklem ax+b=c formatında olmalıdır..");
       for(int i=0;i<isim.length;i++)
    	        deger[i]=sayial(isim[i]+"=");
	double x=(deger[2]-deger[1])/deger[0];
	yazdir("x in degeri="+x);
	}
	
}
class derece2 extends ortak{
	public derece2()
	{
		denkcoz();
	}
	
	String[] isim={"a","b","c","d"}; 
    double[] deger=new double[4];
void denkcoz()
{    yazdir("Denklem ax2+bx+c=d formatında olmalıdır..");
	int sayac=0;
   	for(int i=0;i<isim.length;i++)
   		  deger[i]=sayial(isim[i]+" degeri=");
        	 deger[2]-=deger[3];
         double diskri=Math.sqrt((Math.pow(deger[1],2)-(4*deger[0]*deger[2])));
  if(diskri>=0)
  {       double[] x1x2=new double[2];
  for(int i=-1;i<x1x2.length;i++)
	  if(i!=0)
		  {
		     x1x2[sayac++]=(((-deger[1])+(i*diskri))/2*deger[0]);
		      yazdir("x"+(sayac)+"="+x1x2[sayac-1]);
		  }
  }
  else
	  yazdir("Çözüm boş kümedir");
}
}
public class COZ extends ortak{
	public COZ()
	{
		boolean durum=true;
		while(durum)
		{ 
			yazdir("1-Birinci dereceden denklem çöz");
			yazdir("2-İkinci dereceden denklem çöz");
			yazdir("3-Çıkış");
			int secim=(int)sayial("Secim yapınız=");
			switch(secim)
			{
			case 1:new derece1();break;
			case 2:new derece2();break;
			case 3:durum=false;break;
			}
		}
	}
	void denkcoz() {
		
	}
 public static void main(String[] arg)
 {
	new COZ();
	 
 }
}