-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchByBranch.java
152 lines (134 loc) · 4.51 KB
/
SearchByBranch.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import static javax.swing.JOptionPane.showMessageDialog;
public class SearchByBranch extends JFrame implements ActionListener
{
private JLabel branchL;
private JComboBox branchT;
private JTextArea output;
private JButton search,back;
Container con=null;
String usn="";
String[] branches= {"CSE","ISE","EEE","ECE","MEC","TEC","AIML"};
SearchByBranch()
{
super("Search By Branch");
con = getContentPane();
con.setLayout(null);
Color lightBlue = new Color(0,255,255);
con.setBackground(lightBlue);
con.setSize(300,300);
con.setLayout(null);
con.setVisible(true);
Font font = new Font("Verdana", Font.BOLD, 16);
Color blue = new Color(30,144,255);
branchL=new JLabel("Enter Branch of record to be searched");
branchL.setBounds(300, 50, 700,150);
branchL.setFont(font);
branchL.setForeground(Color.BLACK);
branchT=new JComboBox(branches);
branchT.setBounds(725,100,250,50);
branchT.setFont(font);
branchT.setForeground(Color.BLACK);
output=new JTextArea();
output.setBounds(20,200,1200,350);
output.setFont(font);
output.setForeground(Color.BLACK);
output.setEditable(false);
search = new JButton("Search");
search.setBounds(400,600,150,40);
search.addActionListener(this);
search.setFont(font);
Color pul = new Color(0,0,255);
Border bored = BorderFactory.createLineBorder(pul,5);
search.setBorder(bored);
search.setForeground(Color.WHITE);
search.setBackground(blue);
back = new JButton("Go Back");
back.setBounds(600,600,150,40);
back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
back.setBackground(blue);
con.add(branchL);
con.add(branchT);
con.add(output);
con.add(search);
con.add(back);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==search)
{
String branch1 = (String) branchT.getSelectedItem();
try
{
String name = "", usn ="", sem = "", branch = "", cgpa= "", nob="", company="",ctc="",comments="", r;
File temp = new File("temp.txt");
Boolean createNewFile1 = temp.createNewFile();
BufferedWriter pw = new BufferedWriter(new FileWriter("temp.txt"));
String b = "NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS";
pw.write(b);
pw.write("\n");
BufferedReader br = new BufferedReader(new FileReader("student.txt"));
while((r= br.readLine()) !=null)
{
String[] result = r.split("\\|");
name=result[0];
usn=result[1];
sem= result[2];
branch=result[3];
cgpa=result[4];
nob=result[5];
company=result[6];
ctc=result[7];
comments=result[8];
if(name.equals("999"))
break;
if(branch.equals(branch1)) {
String bb = name + "\t|" + usn + "\t|" + sem + "\t|" + branch + "\t|" + cgpa + "\t|" + nob + "\t|" + company + "\t|" + ctc + "\t|" + comments;
pw.write(bb);
pw.write("\n");
}
}
br.close();
pw.close();
File file = new File("temp.txt");
BufferedReader br1 = new BufferedReader(new FileReader(file));
output.read(br1,null);
br1.close();
output.requestFocus();
file.delete();
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(ae.getSource()==back)
{
try
{
this.dispose();
Search1 h=new Search1();
h.setSize(2300,790);
h.setVisible(true);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public static void main(String args[])
{
Search1 ser=new Search1();
ser.setSize(2300,790);
ser.setVisible(true);
}
}