-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathOTPGenerator.java
More file actions
54 lines (48 loc) · 1.38 KB
/
OTPGenerator.java
File metadata and controls
54 lines (48 loc) · 1.38 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Collections;
public class OTPGenerator
{
public static void frame()
{
JFrame f = new JFrame("OTP Generator");
JLabel l1;
JTextField tf1;
JButton b1;
l1 = new JLabel("OTP is ");
l1.setBounds(20,20,60,15);
tf1 = new JTextField("0000");
tf1.setBounds(70,20,100,15);
tf1.setEditable(false);
b1 = new JButton("create");
b1.setBounds(40,50,100,20);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<=9;i++)
{
list.add(i);
}
Collections.shuffle(list);
int otp = 0;
otp = (list.get(0)*1000)+(list.get(1)*100)+(list.get(2)*10)+(list.get(3));
String str = Integer.toString(otp);
tf1.setText(str);
}
});
f.add(l1);
f.add(tf1);
f.add(b1);
f.setLayout(null);
f.setVisible(true);
f.setSize(400,300);
}
public static void main(String args[])
{
frame();
}
}