Fatura Hesaplama

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.sql.*;
public class Calistir extends JFrame implements ActionListener,ListSelectionListener {
      String[] jlb= {"Ad","SoyAd","Tür","MetreKüp","Tutar"};
	  DefaultListModel<String>[] dlm;
	  JList[] jlist;
	  JTextField[] jtext; 
	  JComboBox<String> jcbtur;
	  DefaultListModel<Integer>[] dlm_id;
	  String[] btn_txt= {"Ekle","Sil","Güncelle"};
	  Connection baglanti;
 	public Calistir() {
       this.setTitle("Su Fatura Hesaplama");
       this.setSize(600, 500);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.setLayout(new FlowLayout());
       
       JPanel jpn_main=new JPanel();//Diğer panellerin kaymaması için
       jpn_main.setPreferredSize(new Dimension(600,500));
        
       Dimension boyut=new Dimension(100,25);
       
       dlm=new DefaultListModel[jlb.length];
       jlist=new JList[dlm.length];
       dlm_id=new DefaultListModel[2];
       jcbtur=new JComboBox<String>();
       jcbtur.setPreferredSize(boyut);
       jtext=new JTextField[3];
       for(int i=0;i<jlb.length;i++) {
    	   JPanel jpn=new JPanel();
    	   jpn.setPreferredSize(new Dimension(100,450));
    	   JLabel jlbl=new JLabel(jlb[i]);
    	   jlbl.setPreferredSize(boyut);
    	   jpn.add(jlbl);
    	   dlm[i]=new DefaultListModel<String>();
    	   jlist[i]=new JList<String>(dlm[i]);
    	   jlist[i].addListSelectionListener(this);
    	   JScrollPane scp=new JScrollPane(jlist[i]);
    	   scp.setPreferredSize(new Dimension(100,300));
    	   jpn.add(scp);
    	   if(i<jtext.length) {
    		   jtext[i]=new JTextField();
    		   jtext[i].setPreferredSize(boyut);
    	   }
    	   if(i<2) {
    		   jpn.add(jtext[i]);
    	   dlm_id[i]=new DefaultListModel<Integer>();
    	   }
    		   if(i==2) 
        	   jpn.add(jcbtur);
        	if(i==3)
        		jpn.add(jtext[i-1]);
         if(i<btn_txt.length)
         {
        	 JButton jbtn=new JButton(btn_txt[i]);
        	 jbtn.setPreferredSize(boyut);
        	 jbtn.addActionListener(this);
        	 jbtn.setActionCommand(btn_txt[i]);
        	 jpn.add(jbtn);
        	 
         }
    	   jpn_main.add(jpn);
       }
       combodoldur();
       listedoldur();
       this.add(jpn_main);
       this.setVisible(true);
	}
	
@Override
public void actionPerformed(ActionEvent arg0) {
		
	   switch(arg0.getActionCommand()) {
	   case "Ekle":ekle();break;
	   case "Sil":sil();break;
	   case "Güncelle":guncelle();break;
	   }
		
	}
public void ekle() {
try {
	
	int secilentur=jcbtur.getSelectedIndex();
	if(jtext[0].getText().length()>0&&jtext[1].getText().length()>0&&secilentur>-1){
		int secilenid=dlm_id[0].getElementAt(secilentur);
	    int miktar=Integer.parseInt(jtext[2].getText());
	    PreparedStatement sorgu=baglanti.prepareStatement("insert into Faturalar(Ad,SoyAd,TurID,MetreKup) values(?,?,?,?)");
	     sorgu.setString(1, jtext[0].getText());
	     sorgu.setString(2, jtext[1].getText());
	     sorgu.setInt(3, secilenid);
	     sorgu.setInt(4, miktar);
	     sorgu.executeUpdate();
	     listedoldur();
	     for(int i=0;i<jtext.length;i++)
	    	 jtext[i].setText("");
	}

} catch (Exception e) {
	JOptionPane.showMessageDialog(this,e.getMessage());
}
}
public void sil() {
	try {
		int secilen=jlist[0].getSelectedIndex();
		if(secilen>-1) {
			PreparedStatement sorgu=baglanti.prepareStatement("delete from Faturalar where ID=?");
			sorgu.setInt(1, dlm_id[1].getElementAt(secilen));
			sorgu.executeUpdate();
			listedoldur();
		}
	} catch (Exception e) {
		JOptionPane.showMessageDialog(this,e.getMessage());
	}
	
}
public void guncelle() {
	try {
		int secilentur=jcbtur.getSelectedIndex();
		int secilen=jlist[0].getSelectedIndex();
		if(jtext[0].getText().length()>0&&jtext[1].getText().length()>0&&secilentur>-1&&secilen>-1){
			int secilenid=dlm_id[0].getElementAt(secilentur);
		    int miktar=Integer.parseInt(jtext[2].getText());
		    PreparedStatement sorgu=baglanti.prepareStatement("update Faturalar set Ad=?,SoyAd=?,TurID=?,MetreKup=? where ID=?");
		     sorgu.setString(1, jtext[0].getText());
		     sorgu.setString(2, jtext[1].getText());
		     sorgu.setInt(3, secilenid);
		     sorgu.setInt(4, miktar);
		     sorgu.setInt(5, dlm_id[1].getElementAt(secilen));
		     sorgu.executeUpdate();
		     listedoldur();
		     for(int i=0;i<jtext.length;i++)
		    	 jtext[i].setText("");
		}

	} catch (Exception e) {
		JOptionPane.showMessageDialog(this,e.getMessage());
	}
}
public void baglan() {

  try {
	baglanti=DriverManager.getConnection("jdbc:sqlite:Fatura.db");
} catch (Exception e) {
	JOptionPane.showMessageDialog(this,e.getMessage());
}
}
public void combodoldur() {
	try {
		baglan();
		PreparedStatement sorgu=baglanti.prepareStatement("select ID,TUR from Turler");
	jcbtur.removeAllItems();
	dlm_id[0].clear();
	ResultSet veri=sorgu.executeQuery();
	
	while(veri.next()) {
		jcbtur.addItem(veri.getString("TUR"));
		dlm_id[0].addElement(veri.getInt("ID"));
		
	}
	} catch (Exception e) {
		JOptionPane.showMessageDialog(this,e.getMessage());
	}
}
public void listedoldur() {
	try {
		baglan();
		PreparedStatement sorgu=baglanti.prepareStatement("select t.Tur as 'Tad',f.ID as 'ID',f.Ad as 'Ad',f.SoyAd as 'SoyAd',f.MetreKup as 'MetreKup',t.M0F as 'M0F',t.M25F as 'M25F',t.M35f as 'M35F' from Faturalar f inner join Turler t on t.ID=f.TurID");
	    ResultSet veri=sorgu.executeQuery();
	  
	    for(int i=0;i<dlm.length;i++)
	    	dlm[i].clear();
	    dlm[1].clear();
	   
	    while(veri.next()) {
	    	
	    	dlm_id[1].addElement(veri.getInt("ID"));
	    	dlm[0].addElement(veri.getString("Ad"));
	    	dlm[1].addElement(veri.getString("SoyAd"));
	    	dlm[2].addElement(veri.getString("Tad"));
	    	double metrekup=veri.getDouble("MetreKup");
	    	dlm[3].addElement(metrekup+"");
	    	double tutar=0;
	    	if(0<metrekup&&metrekup<25)
	    		tutar=metrekup*veri.getInt("M0F");
	    	if(25<metrekup&&metrekup<35)
	    		tutar=metrekup*veri.getInt("M0F")+metrekup*veri.getInt("M25F");
	    	if(metrekup>35)
	    		tutar=metrekup*veri.getInt("M0F")+metrekup*veri.getInt("M25F")+metrekup*veri.getInt("M35F");
	    	dlm[4].addElement(""+tutar);
	    }
	
	} catch (Exception e) {
		JOptionPane.showMessageDialog(this,e.getMessage());
	}
}
 public static void main(String[] arg) {
	 
	 new Calistir();
 }

@Override
public void valueChanged(ListSelectionEvent e) {
	JList secilen=(JList)e.getSource();
	for(int i=0;i<jlist.length;i++)
		jlist[i].setSelectedIndex(secilen.getSelectedIndex());
	
}

}