-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarvellousMain.java
More file actions
196 lines (159 loc) · 5.42 KB
/
MarvellousMain.java
File metadata and controls
196 lines (159 loc) · 5.42 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JLabel;
class MarvellousLogin extends Template implements ActionListener, Runnable
{
JButton SUBMIT;
JLabel label1,label2,label3,TopLabel;
final JTextField text1,text2;
private static int attemp = 3;
MarvellousLogin()
{
TopLabel = new JLabel();
TopLabel.setHorizontalAlignment(SwingConstants.CENTER);
TopLabel.setText("Packer Unpacker : Login");
TopLabel.setForeground(Color.BLUE);
Dimension topsize = TopLabel.getPreferredSize();
TopLabel.setBounds(50,40,topsize.width,topsize.height);
label1 = new JLabel();
label1.setText("Username:");
label1.setForeground(Color.white);
Dimension size = label1.getPreferredSize();
label1.setBounds(50, 135, size.width,size.height);
label1.setHorizontalAlignment(SwingConstants.CENTER);
text1 = new JTextField(15);
Dimension tsize = text1.getPreferredSize();
text1.setBounds(200,135,size.width,size.height);
text1.setToolTipText("ENTER USERNAME");
label2 = new JLabel();
label2.setText("Password:");
label2.setBounds(50,175,size.width,size.height);
label2.setForeground(Color.white);
label2.setHorizontalAlignment(SwingConstants.CENTER);
text2 = new JPasswordField(15);
text2.setBounds(200,175,tsize.width,tsize.height);
text2.setToolTipText("ENTER PASSWORD");
text2.addFocusListener(new FocusListener()
{
public void focusGained(FocusEvent e)
{
}
public void focusLost(FocusEvent e) {
label3.setText("");
}
});
SUBMIT= new JButton("SUBMIT");
SUBMIT.setHorizontalAlignment(SwingConstants.CENTER);
Dimension ssize = SUBMIT.getPreferredSize();
SUBMIT.setBounds(50,220,ssize.width,ssize.height);
label3 = new JLabel();
label3.setText("");
Dimension l3size = label3.getPreferredSize();
label3.setForeground(Color.RED);
label3.setBounds(50,250,l3size.width,l3size.height);
Thread t = new Thread(this);
t.start();
_content.add(label1);
_content.add(text1);
_content.add(label2);
_content.add(text2);
_content.add(label3);
_content.add(SUBMIT);
pack();
validate();
ClockHome();
setVisible(true);
this.setSize(500,500);
this.setResizable(false);
setLocationRelativeTo(null);
SUBMIT.addActionListener(this);
}
public boolean Validate(String Username, String Password)
{
if((Username.length()<8)||(Password.length()<8))
{
return false;
}
else
return true;
}
public void actionPerformed(ActionEvent ae)
{
String value1 = text1.getText();
String value2 = text2.getText();
if(ae.getSource() == exit)
{
this.setVisible(false);
System.exit(0);
}
if(ae.getSource() == minimize)
{
this.setState(this.ICONIFIED);
}
if(ae.getSource() == SUBMIT)
{
if(Validate(value1,value2) == false)
{
text1.setText("");
text2.setText("");
JOptionPane.showMessageDialog(this,"Short username","Marvellous Packer Unpacker",JOptionPane.ERROR_MESSAGE);
}
if(value1.equals("MarvellousAdmin") && value2.equals("MarvellousAdmin"))
{
NextPage page = new NextPage(value1);
this.setVisible(false);
page.pack();
page.setVisible(true);
page.setSize(800,800);
}
else
{
attemp--;
if(attemp == 0)
{
JOptionPane.showMessageDialog(this,"Number of attempts finished","Marvellous Packer Unpacker",JOptionPane.ERROR_MESSAGE);
this.dispose();
System.exit(0);
}
JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
}
}
}
public void run()
{
for(;;)
{
if(text2.isFocusOwner())
{
if( Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK))
{
text2.setToolTipText("Warning : CAPS LOCK is on");
}
else
text2.setToolTipText("");
if((text2.getText()).length()<8)
label3.setText("Weak Password");
else
label3.setText("");
}
}
}
}
class MarvellousMain
{
public static void main(String arg[])
{
try
{
MarvellousLogin frame = new MarvellousLogin();
frame.setVisible(true);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
}