-
Notifications
You must be signed in to change notification settings - Fork 2
/
LoginPageWithFile.java
56 lines (38 loc) · 1.14 KB
/
LoginPageWithFile.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
package Testing;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
public class LoginPageWithFile extends JFrame implements ActionListener{
JLabel label1= new JLabel("USERNAME");
JLabel label2= new JLabel("PASSWORD");
JTextField text1 = new JTextField(10);
JPasswordField text2 = new JPasswordField(10);
JButton b = new JButton("SUBMIT");
LoginPageWithFile() throws IOException{
setVisible(true);
setLayout(new FlowLayout());
setBounds(100,100,200,200);
add(label1);
add(text1);
add(label2);
add(text2);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
try {
FileWriter fr = new FileWriter("MyLoginData.txt",true);
fr.write("User Name :- "+text1.getText()+"\t");
char[] ch = text2.getPassword();
String str = new String(ch);
fr.write("Password :- "+str+"\n");
fr.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
public static void main(String args[]) throws IOException {
LoginPageWithFile l = new LoginPageWithFile();
}
}