-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMSApplication.java
More file actions
206 lines (177 loc) · 4.76 KB
/
CMSApplication.java
File metadata and controls
206 lines (177 loc) · 4.76 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*<applet code=CMSApplication width=400 height=150></applet>*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.applet.*;
@SuppressWarnings("all")
class LoginForm extends JFrame implements ActionListener
{
private JTextField txt_UserName;
private JPasswordField txt_Psswd;
private JButton cmd_OK, cmd_Cancel,cmd_Exit;
private JApplet AppObj;
public LoginForm(String fname, JApplet Tmp)
{
super(fname);
AppObj=Tmp;
txt_UserName=new JTextField(10);
txt_Psswd=new JPasswordField(10);
txt_Psswd.setEchoChar('*');
cmd_OK=new JButton("Login");
cmd_Cancel=new JButton("Reset");
cmd_Exit=new JButton("Exit");
getContentPane().setLayout(new BorderLayout());
JPanel TitlePanel=new JPanel();
TitlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
TitlePanel.add(new JLabel("B. R. Enterprises"));
JPanel panel1=new JPanel();
panel1.setLayout(new FlowLayout());
panel1.add(new Label("Login ID : "));
panel1.add(txt_UserName);
JPanel panel2=new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(new Label("Password : "));
panel2.add(txt_Psswd);
JPanel MainPanel=new JPanel();
MainPanel.setLayout(new BorderLayout());
MainPanel.add(panel1,BorderLayout.NORTH);
MainPanel.add(panel2,BorderLayout.CENTER);
JPanel panel3=new JPanel();
panel3.setLayout(new FlowLayout());
panel3.add(cmd_OK);
panel3.add(cmd_Cancel);
panel3.add(cmd_Exit);
getContentPane().add(TitlePanel,BorderLayout.NORTH);
getContentPane().add(MainPanel,BorderLayout.CENTER);
getContentPane().add(panel3,BorderLayout.SOUTH);
addWindowListener(new MyWindowAdapter());
cmd_OK.addActionListener(this);
cmd_Cancel.addActionListener(this);
cmd_Exit.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==cmd_OK)
{
String u=txt_UserName.getText();
char [] p=txt_Psswd.getPassword();
String ps=new String(p);
if(checkLogin(u, ps))
{
MainForm mform=new MainForm("Main Form");
mform.setSize(300,300);
mform.setResizable(true);
mform.setVisible(true);
setVisible(false);
//displayMesg("Valid Username or Password");
}
else
{
displayMesg("Invalid Username or Password");
}
}
else if(ae.getSource()==cmd_Exit)
{
dispose();
}
else if(ae.getSource()==cmd_Cancel)
{
txt_UserName.setText("");
txt_Psswd.setText("");
}
}
public void displayMesg(String m)
{
MyDialog dialog=new MyDialog(this,m,true);
dialog.setSize(300,100);
dialog.setVisible(true);
}
@SuppressWarnings("all")
class MyWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
dispose();
System.exit(0);
}
}
boolean checkLogin(String user, String pwd)
{
boolean flag=false;
try
{
BufferedReader br=new BufferedReader(new FileReader("login"));
String str=new String();
while((str=br.readLine())!=null)
{
StringTokenizer token=new StringTokenizer(str,"*");
String u=token.nextToken();
String p=token.nextToken();
if(user.equals(u) && pwd.equals(p))
{
flag=true;
break;
}
else
{
flag=false;
}
}
} catch(FileNotFoundException fnfe)
{
displayMesg("Cannot open login file");
}
catch(IOException ioe)
{
displayMesg("I/O Error");
}
catch(Exception e)
{
displayMesg("Error occurred");
}
return flag;
}
}
@SuppressWarnings("all")
public class CMSApplication extends JApplet implements ActionListener
{
private JButton cmd_Login;
private JLabel Lbl1, Lbl2;
public void init()
{
Lbl1=new JLabel("Welcome to Contact Management System!", JLabel.CENTER);
cmd_Login=new JButton("Login");
Font f=new Font("Arial",Font.PLAIN,18);
getContentPane().setLayout(new BorderLayout());
JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
Lbl1.setFont(f);
p1.add(Lbl1);
JPanel p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(cmd_Login);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.NORTH);
getContentPane().add(p2,BorderLayout.CENTER);
cmd_Login.addActionListener(this);
/*LoginForm loginform=new LoginForm("Login Form", this);
loginform.setSize(300,200);
loginform.setResizable(true);
loginform.setVisible(true);*/
}
public void destroy()
{
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==cmd_Login)
{
LoginForm loginform=new LoginForm("Login Form", this);
loginform.setSize(300,200);
loginform.setResizable(true);
loginform.setVisible(true);
}
}
}