Ders programı uygulaması indir

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
public class Calistir extends JFrame implements ActionListener,ListSelectionListener,ItemListener {
	 DefaultListModel<String>[] dlm;
     JList<String>[] jlist;
     String[] lbl= {"Ders","Hoca","Gün","Saat","Teorik","Uygulama"};
     JComboBox<String> jcb;
     JComboBox<Integer> jcb_id;
     JComboBox<Integer> jcb_orgun;
	public Calistir()  {
		this.setTitle("Ders Programı");
		this.setSize(700,450);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new FlowLayout());
		
		String[] btn_txt={"Ders","Hoca","Eşleştirme"};
		JPanel jpn_main=new JPanel();
		jpn_main.setPreferredSize(new Dimension(700, 450));
		
		dlm=new DefaultListModel[lbl.length];
		jlist=new JList[dlm.length];
		
		
		for(int i=0;i<dlm.length;i++) {
			JPanel jpn=new JPanel();
			jpn.setPreferredSize(new Dimension(100, 400));
			
			JLabel jlb=new JLabel(lbl[i]);
			jlb.setPreferredSize(new Dimension(100,25));
			
			dlm[i]=new DefaultListModel<String>();
			jlist[i]=new JList<String>(dlm[i]);
			jlist[i].addListSelectionListener(this);
			JScrollPane jscp=new JScrollPane(jlist[i]);
		    jscp.setPreferredSize(new Dimension(100, 300));
		    
		    jpn.add(jlb);
		    jpn.add(jscp);
		  
		    jpn_main.add(jpn);
		    if(i!=0&&(i-1)<btn_txt.length){
		    	JButton btn=new JButton(btn_txt[i-1]);
		    	btn.setPreferredSize(new Dimension(100,25));
		    	btn.addActionListener(this);
		    	btn.setActionCommand(btn_txt[i-1]);	
		    	jpn.add(btn);
		    }
		    if(i==0) {
		       jcb=new JComboBox<String>();
		       jcb.setSelectedIndex(-1);
		       jcb.setPreferredSize(new Dimension(100, 25));
		       jcb.addItemListener(this);
		       jcb_id=new JComboBox<Integer>(); 
		       jcb_orgun=new JComboBox<Integer>();
		       jpn.add(jcb);   
		    }
		}
		combodoldur();
		if(jcb_id.getItemCount()==0)
		listdoldur(0,0);
		else
		listdoldur(jcb_id.getItemAt(0),jcb_orgun.getItemAt(0));
		this.add(jpn_main);
	   this.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
	
		switch(arg0.getActionCommand()) {
		
		case "Ders":new Ders(this);break;
		case "Hoca":new Hoca(this);break;
		case "Eşleştirme":new Eslestirme(this);break;
		}
	}
 public static void main(String[] arg) {
	 
	 new Calistir();
 }
@Override
public void valueChanged(ListSelectionEvent arg0) {
	JList secilen=(JList)arg0.getSource();
	for(int i=0;i<jlist.length;i++)
		jlist[i].setSelectedIndex(secilen.getSelectedIndex());
}
Connection baglanti;
public void baglan() {
	try {
			baglanti=DriverManager.getConnection("jdbc:sqlite:Ders Programi.db");
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
	
}
public void combodoldur() {
	try {
		baglan();
		PreparedStatement sorgu=baglanti.prepareStatement("select distinct sinif,orgun from dersler");
		ResultSet veri=sorgu.executeQuery();
		jcb.removeAllItems();
	    jcb_id.removeAllItems();
	    jcb_orgun.removeAllItems();
		while(veri.next()) {
			int sinif=veri.getInt("sinif");
			int orgun=veri.getInt("orgun");
			jcb.addItem(sinif+".Sınıf"+"("+orgun+".Örgün"+")");
			jcb_id.addItem(sinif);
			jcb_orgun.addItem(orgun);
			
		}
	} catch (Exception e) {
		JOptionPane.showMessageDialog(this, e.getMessage()+"dsaasds");
	}
	
}
public void listdoldur(int sinif,int orgun) {
	try {
			baglan();
			 String sql="select d.teoriksaati as 'teorik', d.uygsaati as 'uyg', d.sinif as 'sinif',d.orgun as 'orgun',h.hocaismi as 'hoca',d.dersismi as 'ders',s.saad as 'saat',g.isim as 'gun' ,e.tip as 'tip' from eslestirme e inner join hoca h on h.id=e.hocaid inner join gun g on g.id=e.gunid inner join Saat s on s.id=e.saatid	inner join dersler d on d.id=e.dersid 	and e.dersid=d.id  where sinif=? and orgun=?" ;
			 		
			PreparedStatement sorgu=baglanti.prepareStatement(sql);
			sorgu.setInt(1,sinif);
			sorgu.setInt(2, orgun);
			ResultSet veri=sorgu.executeQuery();
		   for(int i=0;i<dlm.length;i++)
			   dlm[i].clear();
			while(veri.next()) {
				dlm[0].addElement(veri.getString("ders"));
				dlm[1].addElement(veri.getString("hoca"));
				dlm[2].addElement(veri.getString("gun"));
				dlm[3].addElement(veri.getString("saat"));
				dlm[4].addElement(veri.getString("teorik"));
				dlm[5].addElement(veri.getString("uyg"));
				
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
}
@Override
public void itemStateChanged(ItemEvent arg0) {
	
          if(arg0.getStateChange()==2) {
	int secilen=jcb.getSelectedIndex();	
	if(secilen>-1) {
	listdoldur(jcb_id.getItemAt(secilen),jcb_orgun.getItemAt(secilen));

}
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
public class Ders extends JFrame implements ActionListener,ListSelectionListener,WindowListener{
      DefaultListModel<String>[] dlm;
      JList<String>[] jlist;
      String[] lbl= {"Ders Ad","Kodu","Teorik Saati","Uyg Saati","Sınıf","Örgün"};
	  JTextField[] jtext;
	  Calistir frm;
      public Ders(Calistir frm) {
    	 this.frm=frm;
    	 frm.setVisible(false);
		this.setTitle("Ders");
		this.setSize(700,450);
		this.addWindowListener(this);
		this.setLayout(new FlowLayout());
		
		JPanel jpn_main=new JPanel();
		jpn_main.setPreferredSize(new Dimension(700, 450));
	   
		dlm=new DefaultListModel[lbl.length];
		jlist=new JList[dlm.length];
		jtext=new JTextField[jlist.length];
		
		for(int i=0;i<dlm.length;i++) {
			JPanel jpn=new JPanel();
			jpn.setPreferredSize(new Dimension(100, 450));
			
			JLabel jlb=new JLabel(lbl[i]);
			jlb.setPreferredSize(new Dimension(100,25));
			
			dlm[i]=new DefaultListModel<String>();
			jlist[i]=new JList<String>(dlm[i]);
			jlist[i].addListSelectionListener(this);
			JScrollPane jscp=new JScrollPane(jlist[i]);
		    jscp.setPreferredSize(new Dimension(100, 300));
		    
		    jtext[i]=new JTextField();
		    jtext[i].setPreferredSize(new Dimension(100, 25));
		    
		    jpn.add(jlb);
		    jpn.add(jscp);
		    jpn.add(jtext[i]);
		    if(i==0) {
		    JButton btn=new JButton("Ekle");
		    btn.setPreferredSize(new Dimension(100, 25));
		    btn.addActionListener(this);
		    jpn.add(btn);	
		    }
		    jpn_main.add(jpn);
		}
		listdoldur();
		this.add(jpn_main);
		this.setVisible(true);
	}
   public boolean kontrol() {
	   int sayac=0;
	   for(int i=0;i<jtext.length;i++)
		    if(jtext[i].getText().length()>0)
		    	sayac++;
	   if(sayac==jtext.length)
		   return true;
	   else
		   return false;
   }
   Connection baglanti;
   public void baglan() {
   	try {
			baglanti=DriverManager.getConnection("jdbc:sqlite:Ders Programi.db");
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
   	
   }
   public void listdoldur() {
   	try {
			baglan();
			PreparedStatement sorgu=baglanti.prepareStatement("select * from dersler");
			ResultSet veri=sorgu.executeQuery();
		   for(int i=0;i<dlm.length;i++)
			   dlm[i].clear();
			while(veri.next()) {
				dlm[0].addElement(veri.getString("dersismi"));
				dlm[1].addElement(veri.getString("kodu"));
				dlm[2].addElement(""+veri.getInt("teoriksaati"));
				dlm[3].addElement(""+veri.getInt("uygsaati"));
				dlm[4].addElement(""+veri.getInt("sinif"));
				dlm[5].addElement(""+veri.getInt("orgun"));
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
   }
   public boolean kontrol_ders() {
	   
	   for(int i=0;i<dlm[0].getSize();i++) {
		   if(dlm[0].getElementAt(i).equals(jtext[0].getText())&&dlm[4].getElementAt(i).equals(jtext[4].getText())&&dlm[5].getElementAt(i).equals(jtext[5].getText()))
	           return false;
	   }
   return true;}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(kontrol()&&kontrol_ders()) {
		   
			try {
				 int teoriks=Integer.parseInt(jtext[2].getText());
				 int uygs=Integer.parseInt(jtext[3].getText());
				 int sinif=Integer.parseInt(jtext[4].getText());
				 int orgun=Integer.parseInt(jtext[5].getText());
			baglan();
			PreparedStatement sorgu=baglanti.prepareStatement("insert into dersler(dersismi,kodu,teoriksaati,uygsaati,sinif,orgun) values(?,?,?,?,?,?)");
		    sorgu.setString(1, jtext[0].getText());
		    sorgu.setString(2, jtext[1].getText());
		    sorgu.setInt(3, teoriks);
		    sorgu.setInt(4, uygs);
		    sorgu.setInt(5, sinif);
		    sorgu.setInt(6, orgun);
		    sorgu.executeUpdate();
		    for(int i=0;i<jtext.length;i++)
		    	jtext[i].setText("");
		    listdoldur();
		    frm.combodoldur();
			} catch (Exception e2) {
			JOptionPane.showMessageDialog(this, e2.getMessage());
		}
		}
	}
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
		JList secilen=(JList)arg0.getSource();
		for(int i=0;i<jlist.length;i++)
			jlist[i].setSelectedIndex(secilen.getSelectedIndex());
		
	}
	@Override
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowClosing(WindowEvent arg0) {
		frm.setVisible(true);
		
	}
	@Override
	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
public class Eslestirme extends JFrame implements ActionListener,ListSelectionListener,WindowListener {
	 DefaultListModel<String>[] dlm;
	 DefaultListModel<Integer>[] dlm_id;
	 DefaultListModel<Integer> dlm_teouyg;
	 DefaultListModel<Integer> dlm_sinifid;
     JList<String>[] jlist;
     String[] lbl= {"Ders","Hoca","Saat","Gün","Tip"};
     JComboBox<String>[] jcb;
     JComboBox<Integer>[] jcb_id;
     Calistir frm;
	public Eslestirme(Calistir frm) {
		 this.frm=frm;
    	 frm.setVisible(false);
		this.setTitle("Eslestirme");
		this.setSize(600,450);
		this.addWindowListener(this);
		this.setLayout(new FlowLayout());
		
		JPanel jpn_main=new JPanel();
		jpn_main.setPreferredSize(new Dimension(600, 450));
	   
		dlm_teouyg=new DefaultListModel<Integer>();
		dlm_sinifid=new DefaultListModel<Integer>();
		dlm=new DefaultListModel[lbl.length];
		dlm_id=new DefaultListModel[lbl.length];
		jlist=new JList[dlm.length];
		jcb=new JComboBox[jlist.length];
		jcb_id=new JComboBox[jlist.length];
		
		for(int i=0;i<dlm.length;i++) {
			JPanel jpn=new JPanel();
			jpn.setPreferredSize(new Dimension(100, 450));
			
			JLabel jlb=new JLabel(lbl[i]);
			jlb.setPreferredSize(new Dimension(100,25));
			
			dlm[i]=new DefaultListModel<String>();
			dlm_id[i]=new DefaultListModel<Integer>();
			jlist[i]=new JList<String>(dlm[i]);
			jlist[i].addListSelectionListener(this);
			JScrollPane jscp=new JScrollPane(jlist[i]);
		    jscp.setPreferredSize(new Dimension(100, 300));
		    
		    jcb[i]=new JComboBox<String>();
		    jcb[i].setPreferredSize(new Dimension(100, 25));
		    jcb_id[i]=new JComboBox<Integer>();
		    
		    jpn.add(jlb);
		    jpn.add(jscp);
		    jpn.add(jcb[i]); 
		    if(i==0) {
		    JButton btn=new JButton("Ekle");
		    btn.setPreferredSize(new Dimension(100, 25));
		    btn.addActionListener(this);
		    jpn.add(btn);	
		    }
		    jpn_main.add(jpn);
		}
		combodoldur();
		listdoldur();
		this.add(jpn_main);
	   this.setVisible(true);
	}
	Connection baglanti;
    public void baglan() {
    	try {
			baglanti=DriverManager.getConnection("jdbc:sqlite:Ders Programi.db");
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
    	
    }
    public void combodoldur() {
    	try {
    		PreparedStatement sorgu=null;
    		ResultSet veri=null;
			baglan();
			sorgu=baglanti.prepareStatement("select id,dersismi,sinif,orgun,teoriksaati,uygsaati from dersler");
		    veri=sorgu.executeQuery();
			jcb[0].removeAllItems();
			jcb_id[0].removeAllItems();
			dlm_teouyg.clear();
			dlm_sinifid.clear();
			while(veri.next()) {
				int sinif_id=veri.getInt("sinif");
				 jcb[0].addItem(veri.getString("dersismi")+"("+sinif_id+"."+veri.getInt("orgun")+"."+"Ögün"+")");
				 jcb_id[0].addItem(veri.getInt("id"));
				 dlm_teouyg.addElement(veri.getInt("teoriksaati")+veri.getInt("uygsaati"));
				 dlm_sinifid.addElement(sinif_id);
			}
			sorgu=baglanti.prepareStatement("select id,hocaismi from hoca");
		    veri=sorgu.executeQuery();
			jcb[1].removeAllItems();
			jcb_id[1].removeAllItems();
			while(veri.next()) {
				 jcb[1].addItem(veri.getString("hocaismi"));
				 jcb_id[1].addItem(veri.getInt("id"));
			}
			sorgu=baglanti.prepareStatement("select id,saad from Saat");
		    veri=sorgu.executeQuery();
			jcb[2].removeAllItems();
			jcb_id[2].removeAllItems();
			while(veri.next()) {
				 jcb[2].addItem(veri.getString("saad"));
				 jcb_id[2].addItem(veri.getInt("id"));	
			}
			sorgu=baglanti.prepareStatement("select id,isim from gun");
		    veri=sorgu.executeQuery();
			jcb[3].removeAllItems();
			jcb_id[3].removeAllItems();
			while(veri.next()) {
				 jcb[3].addItem(veri.getString("isim"));
				 jcb_id[3].addItem(veri.getInt("id"));
			}
			jcb[4].addItem("Teorik");
			jcb[4].addItem("Uygulama");
			jcb_id[4].addItem(1);
			jcb_id[4].addItem(2);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
    }
    public void listdoldur() {
       	try {
    			baglan();
    			PreparedStatement sorgu=baglanti.prepareStatement("select d.sinif as 'sinif',d.orgun as 'orgun',h.id as 'h',s.id as 's',g.id as 'g',d.dersismi as 'ders',h.hocaismi as 'hoca',g.isim as 'gun',s.saad as 'saat' ,e.tip as 'tip' from eslestirme e inner join dersler d on d.id=e.dersid inner join hoca h on h.id=e.hocaid inner join gun g on g.id=e.gunid inner join Saat s on s.id=e.saatid");
    				
    			ResultSet veri=sorgu.executeQuery();
    		   for(int i=0;i<dlm.length;i++)
    			   dlm[i].clear();
    			while(veri.next()) {
    				int sinif_id=veri.getInt("sinif");
    				dlm[0].addElement(veri.getString("ders")+"("+veri.getInt("sinif")+"."+veri.getInt("orgun")+"."+"Ögün"+")");
    				dlm[1].addElement(veri.getString("hoca"));
    				dlm[2].addElement(veri.getString("saat"));
    				dlm[3].addElement(veri.getString("gun"));
    				String tip="Teorik";
    				if(veri.getInt("tip")==2)
    					tip="Uygulama";
    			    dlm[4].addElement(tip);
    			
    			    dlm_id[0].addElement(sinif_id);
    				dlm_id[1].addElement(veri.getInt("h"));
    				dlm_id[2].addElement(veri.getInt("s"));
    				dlm_id[3].addElement(veri.getInt("g"));
    				
    			}
    		} catch (Exception e) {
    			JOptionPane.showMessageDialog(this, e.getMessage());
    		}
       }
    public boolean teouyg_kontrol(String ders,int teouyg_saat) {
    	int sayac=0;
    	for(int i=0;i<dlm[0].getSize();i++) {
    		
    		if(dlm[0].getElementAt(i).equals(ders))
    			sayac++;
    	}
    		if(sayac==teouyg_saat)//teouyg_saat adlı dlm de teo+uyg toplamı var
    			return false;
    return true;}
    public boolean kontrol(int sinif_id,int h_id,int s_id,int g_id) {
    	
    	for(int i=0;i<dlm_id[0].size();i++) {
    		
    		//Hoca aynı saatte ve aynı gunde derse giremez
    		if(h_id==dlm_id[1].getElementAt(i)&&s_id==dlm_id[2].getElementAt(i)&&g_id==dlm_id[3].getElementAt(i))
				return false;
    		//Aynı saatte aynı sınıfa baska bir ders olamaz
			if(dlm_id[0].getElementAt(i)==sinif_id&&s_id==dlm_id[2].getElementAt(i)&&g_id==dlm_id[3].getElementAt(i))
				return false;
    			
    	}
   return true;
    }
	@Override
	public void actionPerformed(ActionEvent e) {
		int secilen_d=jcb[0].getSelectedIndex();
		int secilen_h=jcb[1].getSelectedIndex();
		int secilen_s=jcb[2].getSelectedIndex();
		int secilen_g=jcb[3].getSelectedIndex();
		if(secilen_d>-1&&secilen_h>-1&&secilen_s>-1&&secilen_g>-1) {
		 int d_id=jcb_id[0].getItemAt(secilen_d);
		 int h_id=jcb_id[1].getItemAt(secilen_h);
		 int s_id=jcb_id[2].getItemAt(secilen_s);
		 int g_id=jcb_id[3].getItemAt(secilen_g);
		 int sinif_id=dlm_sinifid.getElementAt(secilen_d);
		 if(kontrol(sinif_id,h_id,s_id,g_id)&&teouyg_kontrol(jcb[0].getItemAt(secilen_d), dlm_teouyg.getElementAt(secilen_d))) {
			 int tip=1;
				if(jcb[4].getItemAt(jcb[4].getSelectedIndex())=="Uygulama")
					tip=2;
			try {
				PreparedStatement sorgu=baglanti.prepareStatement("insert into eslestirme(dersid,hocaid,gunid,saatid,tip) values(?,?,?,?,?)");
			     sorgu.setInt(1, d_id);
			     sorgu.setInt(2, h_id);
			     sorgu.setInt(3, g_id);
			     sorgu.setInt(4, s_id);
			     sorgu.setInt(5, tip);
			     sorgu.executeUpdate();
			     listdoldur();
			     frm.combodoldur();
			     frm.listdoldur(frm.jcb_id.getItemAt(0),frm.jcb_orgun.getItemAt(0));
			} catch (Exception e2) {
				JOptionPane.showMessageDialog(this, e2.getMessage());
		      } 	 
		   }
		 else
			 JOptionPane.showMessageDialog(this, "Aynı gün ve aynı saatte ");
		}
	}
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
		JList secilen=(JList)arg0.getSource();
		for(int i=0;i<jlist.length;i++)
			jlist[i].setSelectedIndex(secilen.getSelectedIndex());
		
	}
	@Override
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowClosing(WindowEvent arg0) {
		frm.setVisible(true);
		
	}
	@Override
	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Hoca extends JFrame implements ActionListener,WindowListener{
      DefaultListModel<String> dlm;
      JList<String> jlist;
      JTextField jtext;
      Calistir frm;
	public Hoca(Calistir frm) {
		 this.frm=frm;
    	 frm.setVisible(false);
		this.setTitle("Hoca");
		this.setSize(150,500);
		this.addWindowListener(this);
		this.setLayout(new FlowLayout());
		
		JPanel jpn=new JPanel();
		jpn.setPreferredSize(new Dimension(150, 500));
        
		dlm=new DefaultListModel<String>();
		jlist=new JList<String>(dlm);
	
		JScrollPane jscp=new JScrollPane(jlist);
		jscp.setPreferredSize(new Dimension(100, 300));
		 
		jtext=new JTextField();
		jtext.setPreferredSize(new Dimension(100, 25));
		
		JButton btn=new JButton("Ekle");
		btn.setPreferredSize(new Dimension(100, 25));
		btn.addActionListener(this);
		JLabel jlb=new JLabel("Hocalar");
		jlb.setPreferredSize(new Dimension(100,25));
	   
		jpn.add(jlb);
		jpn.add(jscp);
		jpn.add(jtext);
		jpn.add(btn);
		listdoldur();
		this.add(jpn);
	    this.setVisible(true);
	}
	Connection baglanti;
    public void baglan() {
    	try {
			baglanti=DriverManager.getConnection("jdbc:sqlite:Ders Programi.db");
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
    	
    }
    public void listdoldur() {
    	try {
			baglan();
			PreparedStatement sorgu=baglanti.prepareStatement("select hocaismi from hoca");
			ResultSet veri=sorgu.executeQuery();
			dlm.clear();
			while(veri.next()) {
				dlm.addElement(veri.getString("hocaismi"));
				
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
    }
	@Override
	public void actionPerformed(ActionEvent arg0) {
	  
		   if(jtext.getText().length()>0) {
    try {
		PreparedStatement sorgu=baglanti.prepareStatement("insert into hoca(hocaismi) values(?)");
		sorgu.setString(1, jtext.getText());
		sorgu.executeUpdate();
		jtext.setText("");
		listdoldur();
	} catch (Exception e) {
		JOptionPane.showMessageDialog(this, e.getMessage());
	}
	}
	}
	@Override
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowClosing(WindowEvent arg0) {
			frm.setVisible(true);
		
	}
	@Override
	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}

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

}

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