1 package logacces;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6
7 public class LogAcces extends JFrame {
8 public static void main(String[] args) {
9 SwingUtilities.invokeLater(() -> {
10 new LogAcces();
11 });
12 }
13
14 public LogAcces() {
15 try {
16 UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
17 } catch (Exception e) {
18 e.printStackTrace();
19 }
20 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21 setTitle("Procedura di Loggin");
22 getContentPane().setLayout(null);
23
24 setSize(400, 300);
25 setLocationRelativeTo(null);
26 setVisible(true);
27
28 JLabel lblTit = new JLabel();
29 lblTit.setFont(new Font("Arial", Font.BOLD, 20));
30 lblTit.setText("Inserisci le Tue Credenziali");
31 lblTit.setBounds(30, 5, 300, 30);
32
33 JLabel lblUsr = new JLabel();
34 lblUsr.setHorizontalAlignment(SwingConstants.RIGHT);
35 lblUsr.setFont(new Font("Arial", Font.PLAIN, 16));
36 lblUsr.setText("Inserisci Username:");
37 lblUsr.setBounds(30, 48, 160, 30);
38
39 JLabel lblPsw = new JLabel();
40 lblPsw.setHorizontalAlignment(SwingConstants.RIGHT);
41 lblPsw.setFont(new Font("Arial", Font.PLAIN, 16));
42 lblPsw.setText("Inserisci Password:");
43 lblPsw.setBounds(30, 78, 160, 30);
44
45 JLabel lblOut = new JLabel();
46 lblOut.setHorizontalAlignment(SwingConstants.CENTER);
47 lblOut.setFont(new Font("Arial", Font.BOLD, 14));
48 lblOut.setBounds(80, 180, 200, 40);
49
50 JTextField jtxUsr = new JTextField("me@cersil.it");
51 jtxUsr.setFont(new Font("Arial", Font.PLAIN, 14));
52 jtxUsr.setBounds(195, 50, 150, 30);
53
54 JPasswordField jtxPsw = new JPasswordField("student");
55 jtxPsw.setEchoChar('\u2022');
56 jtxPsw.setFont(new Font("Arial", Font.PLAIN, 14));
57 jtxPsw.setBounds(195, 80, 150, 30);
58
59 JButton button = new JButton("Accedi");
60 button.setBounds(265, 130, 80, 30);
61
62 JCheckBox chkVedi = new JCheckBox("Vedi");
63 chkVedi.setFont(new Font("Arial", Font.PLAIN, 14));
64 chkVedi.setBounds(210, 125, 150, 30);
65 chkVedi.addActionListener(new ActionListener() {
66 public void actionPerformed(ActionEvent e) {
67
68 if (chkVedi.isSelected()) {
69 jtxPsw.setEchoChar((char) 0);
70 } else {
71 jtxPsw.setEchoChar('\u2022');
72 }
73 }
74 });
75
76 button.addActionListener(new ActionListener() {
77 public void actionPerformed(ActionEvent e) {
78
79 String username = jtxUsr.getText();
80 String password = new String(jtxPsw.getPassword());
81 if (username.equals("me@cersil.it") && password.equals("student")) {
82 lblOut.setText("Accesso consentito");
83 lblOut.setForeground(Color.black);
84 } else {
85 lblOut.setText("Accesso negato");
86 lblOut.setForeground(Color.RED);
87 }
88 }
89 });
90
91 add(lblTit);
92 add(lblUsr);
93 add(lblPsw);
94 add(lblOut);
95 add(jtxUsr);
96 add(jtxPsw);
97 add(button);
98 add(chkVedi);
99 }
100 } |