-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteDetails.java
73 lines (56 loc) · 1.84 KB
/
DeleteDetails.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.ArrayList;
public class DeleteDetails extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
JLabel l1;
JTextField tf1;
JButton b;
DeleteDetails()
{
super("Delete Details of Student :- ");
l1=new JLabel("R. No ");
l1.setBounds(50,70,150,20);
tf1=new JTextField();
tf1.setBounds(150,70,200,20);
b=new JButton("Submit");
b.setBounds(50,200,80,30);
b.addActionListener(this);
add(l1);
add(tf1);
add(b);
setSize(600,700);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
String rno = tf1.getText();
ArrayList<Details> a= new ArrayList<Details>();
try {
FileInputStream fin = new FileInputStream("D:\\Details.ser");
ObjectInputStream in = new ObjectInputStream(fin);
Details d;
while (true) {
d = (Details) in.readObject();
a.add(d);
}
}
catch (Exception eof) {
}
try {
FileOutputStream fout = new FileOutputStream("D:\\Details.ser");
ObjectOutputStream out = new ObjectOutputStream(fout);
for(Details det : a)
if(!det.rno.equals(rno))
out.writeObject(det);
out.close();
fout.close();
}
catch (IOException i) {
i.printStackTrace();
}
}
}