-
Notifications
You must be signed in to change notification settings - Fork 0
/
swing_ex1.java
39 lines (38 loc) · 1.05 KB
/
swing_ex1.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class swing_ex1 extends JFrame implements ActionListener{
JLabel l1, l2;
JTextField t1, t2;
JButton b;
public swing_ex1()
{
l1 = new JLabel("Username");
l2 = new JLabel("Password:");
t1 = new JTextField(20);
t2 = new JTextField(20);
b = new JButton("Login");
setLayout(new FlowLayout());
add(l1); add(t1);
add(l2); add(t2);
b.addActionListener(this);
add(b);
setSize(400, 500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
String name = t1.getText();
String pass = t2.getText();
if(name.equals("Admin") && pass.equals("PTF@112022"))
{
JOptionPane.showMessageDialog(this, "Login Sucsess");
}
else
JOptionPane.showMessageDialog(this, "Login Failed");
}
public static void main(String[] args) {
new swing_ex1();
}
}