-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchRemindForm.java
More file actions
189 lines (164 loc) · 4.89 KB
/
SearchRemindForm.java
File metadata and controls
189 lines (164 loc) · 4.89 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
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
@SuppressWarnings("all")
public class SearchRemindForm extends JFrame implements ActionListener
{
private static String [] Months={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
private static String [] Col_Heading={"Entry ID","Name","Day","Month","Year","Remarks"};
private JComboBox cho_Mon;
private JTable tt;
private JButton cmd_Search,cmd_Cancel;
JPanel panel2;
Object data[][];
public SearchRemindForm(String fname)
{
super(fname);
Vector v=new Vector();
getContentPane().setLayout(new BorderLayout());
for(int i=0;i<12;i++)
v.addElement(Months[i]);
//Add values in month combobox.
cho_Mon=new JComboBox(v);
cmd_Search=new JButton("Search");
cmd_Cancel=new JButton("Back");
JPanel panel1=new JPanel();
panel1.setLayout(new FlowLayout());
panel1.add(cho_Mon);
panel2=new JPanel();
panel2.setLayout(new FlowLayout(FlowLayout.LEFT));
JPanel panel3=new JPanel();
panel3.setLayout(new FlowLayout(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(new MyWindowAdapter());
}
public void actionPerformed(ActionEvent ae)
{
//If user clicks on Search button.
if(ae.getSource()==cmd_Search)
{
//Gets the total count for records in the Annivers file.
int count=getCount();
try
{
BufferedReader br=new BufferedReader(new FileReader("Reminder"));
String str=new String();
int i=0;
boolean flag=false;
StringTokenizer t;
data=new Object[count][6];
flag=false;
while((str=br.readLine())!=null)
{
StringTokenizer token=new StringTokenizer(str,"*");
t=new StringTokenizer(str,"*");
String eid=t.nextToken();
String name=t.nextToken();
String dd=t.nextToken();
String mm=t.nextToken();
String yy=t.nextToken();
String rem=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(int j=0;j<6;j++)
{
data[i][j]=token.nextElement();
}
i++;
}
}
br.close();
if(flag==false)
{
displayMesg("No record found");
}
else
{
panel2.removeAll();
tt=new JTable(data,Col_Heading);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane sc=new JScrollPane(tt);
panel2.add(sc);
pack();
repaint();
}
} catch(FileNotFoundException fnfe)
{
}
catch(IOException ioe)
{
displayMesg("I/O error");
}
}
else if(ae.getSource()==cmd_Cancel)
{
SearchForm sform=new SearchForm("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.
int getCount()
{ int count=0;
try
{
BufferedReader br=new BufferedReader(new FileReader("Reminder"));
String str;
while((str=br.readLine())!=null)
{
StringTokenizer token=new StringTokenizer(str,"*");
String eid=token.nextToken();
String n=token.nextToken();
String d=token.nextToken();
String m=token.nextToken();
if(m.equals((String)cho_Mon.getSelectedItem()))
{
count++;
}
}
br.close();
} catch(FileNotFoundException fnfe)
{
displayMesg("Reminder file not found");
setVisible(false);
dispose();
}
catch(IOException ioe)
{
displayMesg("I/O error");
}
return count;
}
//Inner class to implement windowClosing() method.
class MyWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
SearchForm sform=new SearchForm("Search Contact Form");
sform.setSize(250,250);
sform.setResizable(false);
sform.setVisible(true);
dispose();
}
}
public void displayMesg(String m)
{
MyDialog dialog=new MyDialog(this,m,true);
dialog.setLocation(this.getX(),this.getY());
dialog.setSize(300,100);
dialog.setVisible(true);
}
}