Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 1.37 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. only first contact gets deleted
  2. public void deleteActionPerformed(ActionEvent ae) {
  3.   String delname=tf4.getText();
  4.   int c=0;
  5.   try {
  6.     ObjectInputStream ois=new ObjectInputStream(new FileInputStream("data.txt"));
  7.     data=(Object[][])ois.readObject();
  8.  
  9.     for(;;c++) {
  10.       String x=(String)data[c][0];
  11.       if(x.equals(delname)) {
  12.         System.out.println("if working");
  13.         data[c][0]=null;
  14.         data[c][1]=null;
  15.         data[c][2]=null;
  16.         try {
  17.           ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("data.txt"));
  18.           oos.writeObject(data);
  19.         } catch(Exception exc) {
  20.           System.out.println("error deleting data from"+" "+c+" row");
  21.         }
  22.         c++;
  23.         JOptionPane.showMessageDialog(new JFrame(),"contact deleted");
  24.         try {
  25.           ObjectInputStream oist=new ObjectInputStream(new FileInputStream("data.txt"));
  26.           data=(Object[][])oist.readObject();      
  27.           JTable tb=new JTable(data,headers);
  28.           ObjectOutputStream oost=new ObjectOutputStream(new FileOutputStream("contacts.txt"));
  29.           oost.writeObject(tb);
  30.         } catch(Exception exc) {
  31.           System.out.println("error updating after deleting");
  32.         }
  33.  
  34.       }
  35.       else
  36.         System.out.println("else working");
  37.  
  38.  
  39.     }
  40.   } catch(Exception exc) {
  41.     System.out.println("error reading data.txt for deleting");
  42.   }  
  43. }