- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchBirthdayForm.java
More file actions
Latest commit
190 lines (163 loc) · 4.86 KB
/
Copy pathSearchBirthdayForm.java
File metadata and controls
190 lines (163 loc) · 4.86 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
importjava.io.*;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.util.*;
@SuppressWarnings("all")
publicclassSearchBirthdayFormextendsJFrameimplementsActionListener
{
privatestaticString [] Months={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
privatestaticString [] Col_Heading={"Entry ID","Name","Day","Month","Year"};
privateJComboBoxcho_Mon;
privateJTablett;
privateJButtoncmd_Search,cmd_Cancel;
JPanelpanel2;
Objectdata[][];
publicSearchBirthdayForm(Stringfname)
{
super(fname);
Vectorv=newVector();
getContentPane().setLayout(newBorderLayout());
for(inti=0;i<12;i++)
v.addElement(Months[i]);
//Add values in month combobox.
cho_Mon=newJComboBox(v);
cmd_Search=newJButton("Search");
cmd_Cancel=newJButton("Back");
JPanelpanel1=newJPanel();
panel1.setLayout(newFlowLayout());
panel1.add(cho_Mon);
panel2=newJPanel();
panel2.setLayout(newFlowLayout(FlowLayout.LEFT));
JPanelpanel3=newJPanel();
panel3.setLayout(newFlowLayout(FlowLayout.CENTER));
panel3.add(cmd_Search);
panel3.add(cmd_Cancel);
getContentPane().add(panel1,BorderLayout.NORTH);
getContentPane().add(panel2,BorderLayout.CENTER);
getContentPane().add(panel3,BorderLayout.SOUTH);
cmd_Search.addActionListener(this);
cmd_Cancel.addActionListener(this);
addWindowListener(newMyWindowAdapter());
}
publicvoidactionPerformed(ActionEventae)
{
//If user clicks on Search button.
if(ae.getSource()==cmd_Search)
{
//Gets the total count for records in the Annivers file.
intcount=getCount();
try
{
BufferedReaderbr=newBufferedReader(newFileReader("Birthday"));
Stringstr=newString();
inti=0;
booleanflag=false;
StringTokenizert;
data=newObject[count][5];
flag=false;
while((str=br.readLine())!=null)
{
StringTokenizertoken=newStringTokenizer(str,"*");
t=newStringTokenizer(str,"*");
Stringeid=t.nextToken();
Stringname=t.nextToken();
Stringdd=t.nextToken();
Stringmm=t.nextToken();
Stringyy=t.nextToken();
//If current record matches selected entry then add it to the Object array.
if(mm.equals((String)cho_Mon.getSelectedItem()))
{
flag=true;
for(intj=0;j<5;j++)
{
data[i][j]=token.nextElement();
}
i++;
}
}
br.close();
if(flag==false)
{
displayMesg("No record found");
}
else
{
panel2.removeAll();
tt=newJTable(data,Col_Heading);
intv=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
inth=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPanesc=newJScrollPane(tt);
panel2.add(sc);
pack();
repaint();
}
} catch(FileNotFoundExceptionfnfe)
{
}
catch(IOExceptionioe)
{
displayMesg("I/O error");
}
}
elseif(ae.getSource()==cmd_Cancel)
{
SearchFormsform=newSearchForm("Search Contact Form");
sform.setSize(250,250);
sform.setResizable(false);
sform.setVisible(true);
dispose();
}
}
//Returns the total count for total records in the Annivers file.
intgetCount()
{ intcount=0;
try
{
BufferedReaderbr=newBufferedReader(newFileReader("Birthday"));
Stringstr;
while((str=br.readLine())!=null)
{
StringTokenizertoken=newStringTokenizer(str,"*");
Stringeid=token.nextToken();
Stringn=token.nextToken();
Stringd=token.nextToken();
Stringm=token.nextToken();
if(m.equals((String)cho_Mon.getSelectedItem()))
{
count++;
}
}
br.close();
} catch(FileNotFoundExceptionfnfe)
{
displayMesg("Birthday file not found");
setVisible(false);
dispose();
}
catch(IOExceptionioe)
{
displayMesg("I/O error");
}
returncount;
}
//Inner class to implement windowClosing() method.
classMyWindowAdapterextendsWindowAdapter
{
publicvoidwindowClosing(WindowEventwe)
{
SearchFormsform=newSearchForm("Search Contact Form");
sform.setSize(250,250);
sform.setResizable(false);
sform.setVisible(true);
dispose();
}
}
publicvoiddisplayMesg(Stringm)
{
MyDialogdialog=newMyDialog(this,m,true);
dialog.setLocation(this.getX(),this.getY());
dialog.setSize(300,100);
dialog.setVisible(true);
}
}