Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.62 KB | None | 0 0
  1. package lab.pkg11;
  2. import java.awt.BorderLayout;
  3. import java.awt.GridLayout;
  4. import javax.swing.*;
  5. import javax.swing.JOptionPane;
  6. import java.awt.event.*;
  7. import javax.swing.event.AncestorListener;
  8. class Handelevent extends JFrame{
  9.     public Handelevent(){
  10.         JButton jbt_ok = new JButton("Login");
  11.         JButton jbt_cancel = new JButton("Resister");
  12.         JPanel panel = new JPanel();
  13.         panel.add(jbt_ok);
  14.         panel.add(jbt_cancel);
  15.         add(panel);
  16.         OkListener listener1 = new OkListener();
  17.         CancelListener listener2 = new CancelListener();
  18.         jbt_ok.addActionListener(listener1);
  19.         jbt_cancel.addActionListener(listener2);
  20.     }
  21. }
  22. class Login extends JFrame implements ActionListener{
  23.     public Login(){
  24.         JPanel panel;
  25.         JLabel user_label, password_label, message;
  26.         JTextField userName_text;
  27.         JPasswordField password_text;
  28.         JButton submit, cancel;
  29.         user_label = new JLabel();
  30.       user_label.setText("User Name :");
  31.       userName_text = new JTextField();
  32.       password_label = new JLabel();
  33.       password_label.setText("Password :");
  34.       password_text = new JPasswordField();
  35.       submit = new JButton("SUBMIT");
  36.       panel = new JPanel(new GridLayout(6, 0));
  37.       panel.add(user_label);
  38.       panel.add(userName_text);
  39.       panel.add(password_label);
  40.       panel.add(password_text);
  41.  
  42.       message = new JLabel();
  43.       panel.add(message);
  44.       panel.add(submit);
  45.  
  46.       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47.  
  48.       // Adding the listeners to components..
  49.       submit.addActionListener(this);
  50.       add(panel, BorderLayout.CENTER);
  51.       setTitle("Please Login Here !");
  52.       setSize(450,350);
  53.       Namel listener1 = new Namel();
  54.       userName_text.addAncestorListener( listener1);
  55.       setVisible(true);
  56.    }
  57.     class Namel implements ActionListener{
  58.     public void actionPerformed(ActionEvent e){
  59.         String userName = userName_text.getText();
  60.         /*String s;
  61.         s = JOptionPane.showInputDialog(null,"Name : ","Resister",JOptionPane.INFORMATION_MESSAGE);
  62.         String name = s;
  63.         s = JOptionPane.showInputDialog(null,"Email : ","Resister",JOptionPane.INFORMATION_MESSAGE);
  64.         String email = s;
  65.         s = JOptionPane.showInputDialog(null,"Password : ","Resister",JOptionPane.INFORMATION_MESSAGE);
  66.         int pass = Integer.parseInt(s);
  67.         JOptionPane.showMessageDialog(null,"Resistered Successful","Resister",JOptionPane.INFORMATION_MESSAGE);*/
  68.     }
  69. }
  70.     @Override
  71.     public void actionPerformed(ActionEvent ae) {
  72.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  73.     }
  74.     }
  75. public class Lab11 {
  76.     public static void main(String[] args) {
  77.         JFrame frame = new Handelevent();
  78.         frame.setTitle("Handelevent");
  79.         frame.setSize(150, 110);
  80.         frame.setLocation(550, 350);
  81.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  82.         frame.setVisible(true);
  83.     }
  84. }
  85. class OkListener implements ActionListener{
  86.     public void actionPerformed(ActionEvent e){
  87.         JFrame x = new Login();
  88.         x.setSize(250, 250);
  89.         x.setLocation(550, 300);
  90.         /*String s;
  91.         s = JOptionPane.showInputDialog(null,"Name : ","Resister",JOptionPane.INFORMATION_MESSAGE);
  92.         String name = s;
  93.         s = JOptionPane.showInputDialog(null,"Email : ","Resister",JOptionPane.INFORMATION_MESSAGE);
  94.         String email = s;
  95.         s = JOptionPane.showInputDialog(null,"Password : ","Resister",JOptionPane.INFORMATION_MESSAGE);
  96.         int pass = Integer.parseInt(s);
  97.         JOptionPane.showMessageDialog(null,"Resistered Successful","Resister",JOptionPane.INFORMATION_MESSAGE);*/
  98.     }
  99. }
  100. class CancelListener implements ActionListener{
  101.     public void actionPerformed(ActionEvent e){
  102.         String s;
  103.         s = JOptionPane.showInputDialog(null,"Email : ","Login",JOptionPane.INFORMATION_MESSAGE);
  104.         String email = s;
  105.         s = JOptionPane.showInputDialog(null,"Password : ","Login",JOptionPane.INFORMATION_MESSAGE);
  106.         int pass = Integer.parseInt(s);
  107.         JOptionPane.showMessageDialog(null,"Login Successful","Login",JOptionPane.INFORMATION_MESSAGE);
  108.     }  
  109. }
  110. public void actionPerformed(ActionEvent ae) {
  111.       String userName = userName_text.getText();
  112.       String password = password_text.getText();
  113.       if (userName.trim().equals("admin") && password.trim().equals("admin")) {
  114.          message.setText(" Hello " + userName + "");
  115.       } else {
  116.          message.setText(" Invalid user.. ");
  117.       }
  118.    }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement