--------------------------------------------------------------------------------
basit bir tel rehberi. kayıt ediyor,isim girilince girilen ismin telefonunu ekrana mesaj olark veriyor.
package tlf;
import java.io.*;
import java.util.StringTokenizer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @author S33006
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class PhoneBook extends JFrame implements ActionListener{
FileWriter cikti;
JLabel lbl1;
JLabel lbl2;
JTextField txt1;
JTextField txt2;
JButton bt1;
JButton bt2;
JButton bt3;
Container c;
File f = new File("rehber.txt");
public static **** main(String[] args){
JFrame jf = new PhoneBook ();
jf.setVisible(true);
}
public PhoneBook (){
super("telefon rehberi");
c = getContentPane() ;
c.setLayout(new GridLayout(4,2));
this.setSize(new Dimension(257, 118));
lbl1 = new JLabel ("AD SOYAD: ");
c.add(lbl1);
txt1 = new JTextField (15);
c.add(txt1);
lbl2 = new JLabel ("TELEFON NO: ");
c.add(lbl2);
txt2 = new JTextField (15);
c.add(txt2);
bt1= new JButton("KAYDET");
bt1.addActionListener( this);
c.add(bt1);
bt2 = new JButton(" NO GOSTER");
bt2.addActionListener( this);
c.add(bt2);
bt3 = new JButton("TEMİZLE");
bt3.addActionListener( this);
c.add(bt3);
setVisible( true);
}
public **** actionPerformed(ActionEvent e){
if(e.getSource() == bt1){
try
{
cikti = new FileWriter("rehber.txt",true);
cikti.write(txt1.getText()+"\t"+txt2.getText());
cikti.write("\n");
cikti.close();
}catch(Exception ex) {
JOptionPane.showMessageDialog(null,"dosya doğru açılmadı" );
System.exit(1);
}
}
//ad soyad bolumune aranılan isim giriliyor, "NO GOSTER" tuşuna basınca mesaj olarak numara geliyor
else if(e.getSource() == bt2){
try {
InputStreamReader fis = new FileReader(f);
BufferedReader buf = new BufferedReader(fis);
String line = "";
boolean isFound = false;
while ( (line = buf.readLine()) != null) {
StringTokenizer token = new StringTokenizer(line,"\t");
if(token.nextToken().equals(txt1.getText())){
isFound = true;
JOptionPane.showMessageDialog(null,token.nextToken () );
break;
}
}
if(!isFound)
JOptionPane.showMessageDialog(null,"ARADIĞINIZ İSİMDE BİR KAYIT BULUNAMADI!" );
}
catch (Exception el) {
}
}else if(e.getSource() == bt3){
txt1.setText("");
txt2.setText("");
}
}
}