Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Login;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JSeparator;
- import javax.swing.JTextField;
- import javax.swing.JPasswordField;
- import javax.swing.JCheckBox;
- import java.awt.Font;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JToggleButton;
- import javax.swing.JTextPane;
- public class LI {
- private JFrame frame;
- private JTextField textField;
- private JPasswordField passwordField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- LI window = new LI();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public LI() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame("Log In v1.1");
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JLabel LogIa = new JLabel("Log In");
- LogIa.setFont(new Font("Tahoma", Font.BOLD, 14));
- LogIa.setBounds(179, 24, 78, 31);
- frame.getContentPane().add(LogIa);
- JLabel username = new JLabel("Username");
- username.setBounds(44, 91, 71, 14);
- frame.getContentPane().add(username);
- JLabel password = new JLabel("Password");
- password.setBounds(44, 145, 71, 14);
- frame.getContentPane().add(password);
- JSeparator separator = new JSeparator();
- separator.setBounds(44, 193, 326, -4);
- frame.getContentPane().add(separator);
- JSeparator separator_1 = new JSeparator();
- separator_1.setBounds(44, 53, 326, 2);
- frame.getContentPane().add(separator_1);
- textField = new JTextField();
- textField.setBounds(150, 88, 127, 20);
- frame.getContentPane().add(textField);
- textField.setColumns(10);
- passwordField = new JPasswordField();
- passwordField.setBounds(150, 142, 127, 20);
- frame.getContentPane().add(passwordField);
- JCheckBox rembUser = new JCheckBox("Remember Username");
- rembUser.setFont(new Font("Tahoma", Font.PLAIN, 9));
- rembUser.setBounds(237, 112, 133, 23);
- frame.getContentPane().add(rembUser);
- JButton btnLogIn = new JButton("Log In");
- btnLogIn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String username = textField.getText();
- @SuppressWarnings("deprecation")
- String password = passwordField.getText();
- if (username.contains("admin") && password.contains("admin") && rembUser.isSelected()==false) {
- passwordField.setText(null);
- textField.setText(null);
- }
- else if (rembUser.isSelected()==true ){
- JOptionPane.showMessageDialog(null, "Invaild Details","Login Failed", JOptionPane.ERROR_MESSAGE);
- passwordField.setText(null);
- }
- else if (username.contains("admin") && password.contains("admin") && rembUser.isSelected()==true ) {
- passwordField.setText(null);
- }
- else if (username.isEmpty() || password.isEmpty()) {
- JOptionPane.showMessageDialog(btnLogIn, "Password or Username is not filled!", "Invaild Login", JOptionPane.INFORMATION_MESSAGE);
- }
- else {
- JOptionPane.showMessageDialog(btnLogIn, "Invaild Details", "Login Failed", JOptionPane.ERROR_MESSAGE);
- }
- }
- });
- btnLogIn.setBounds(44, 201, 89, 23);
- frame.getContentPane().add(btnLogIn);
- JButton btnReset = new JButton("Reset");
- btnReset.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(rembUser.isSelected()==true ) {
- passwordField.setText(null);
- }
- else {
- textField.setText(null);
- passwordField.setText(null);
- }
- }
- });
- btnReset.setBounds(168, 200, 89, 23);
- frame.getContentPane().add(btnReset);
- JButton btnExit = new JButton("Exit");
- btnExit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if ( JOptionPane.showConfirmDialog(btnExit, "Are you sure you want to exit ?" ,"Exit " , JOptionPane.YES_NO_OPTION)== JOptionPane.YES_NO_OPTION) {
- System.exit(0);
- }
- }
- });
- btnExit.setFont(new Font("Tahoma", Font.BOLD, 11));
- btnExit.setBounds(281, 201, 89, 23);
- frame.getContentPane().add(btnExit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement