Skip to content

Instantly share code, notes, and snippets.

@uncoded-ro
Created June 14, 2022 07:32
Show Gist options
  • Save uncoded-ro/2c93c09045f52b4f385d218b1916ac4a to your computer and use it in GitHub Desktop.
Save uncoded-ro/2c93c09045f52b4f385d218b1916ac4a to your computer and use it in GitHub Desktop.
package ro.virtualcampus.gui;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TextFieldPanel extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private JTextField username, password;
private JButton submit;
private JLabel text1, text2;
private static final String USER = "stud";
private static final String PASS = "stud";
public TextFieldPanel() {
setLayout(new GridLayout(4, 1));
JPanel panou = new JPanel();
panou.setLayout(new GridLayout(2, 2));
text1 = new JLabel("Introduceti numele de utilizator si parola: ");
username = new JTextField();
password = new JPasswordField();
submit = new JButton("Submit");
text2 = new JLabel("");
add(text1);
panou.add(new JLabel("Username: "));
panou.add(username);
panou.add(new JLabel("Password: "));
panou.add(password);
add(panou);
add(submit);
add(text2);
username.addActionListener(this);
password.addActionListener(this);
submit.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "Submit") {
if ((username.getText().length() != 0) && (password.getText().length() != 0))
if ((username.getText().equals(USER)) && (password.getText().equals(PASS)))
text2.setText("Datele introduse sunt corecte!");
else
text2.setText("Datele introduse nu sunt valide!");
else
text2.setText("Nu ati introdus numele de utilizator si parola!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment