Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab.pkg11;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import javax.swing.*;
- import javax.swing.JOptionPane;
- import java.awt.event.*;
- import javax.swing.event.AncestorListener;
- class Handelevent extends JFrame{
- public Handelevent(){
- JButton jbt_ok = new JButton("Login");
- JButton jbt_cancel = new JButton("Resister");
- JPanel panel = new JPanel();
- panel.add(jbt_ok);
- panel.add(jbt_cancel);
- add(panel);
- OkListener listener1 = new OkListener();
- CancelListener listener2 = new CancelListener();
- jbt_ok.addActionListener(listener1);
- jbt_cancel.addActionListener(listener2);
- }
- }
- class Login extends JFrame implements ActionListener{
- public Login(){
- JPanel panel;
- JLabel user_label, password_label, message;
- JTextField userName_text;
- JPasswordField password_text;
- JButton submit, cancel;
- user_label = new JLabel();
- user_label.setText("User Name :");
- userName_text = new JTextField();
- password_label = new JLabel();
- password_label.setText("Password :");
- password_text = new JPasswordField();
- submit = new JButton("SUBMIT");
- panel = new JPanel(new GridLayout(6, 0));
- panel.add(user_label);
- panel.add(userName_text);
- panel.add(password_label);
- panel.add(password_text);
- message = new JLabel();
- panel.add(message);
- panel.add(submit);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // Adding the listeners to components..
- submit.addActionListener(this);
- add(panel, BorderLayout.CENTER);
- setTitle("Please Login Here !");
- setSize(450,350);
- Namel listener1 = new Namel();
- userName_text.addAncestorListener( listener1);
- setVisible(true);
- }
- class Namel implements ActionListener{
- public void actionPerformed(ActionEvent e){
- String userName = userName_text.getText();
- /*String s;
- s = JOptionPane.showInputDialog(null,"Name : ","Resister",JOptionPane.INFORMATION_MESSAGE);
- String name = s;
- s = JOptionPane.showInputDialog(null,"Email : ","Resister",JOptionPane.INFORMATION_MESSAGE);
- String email = s;
- s = JOptionPane.showInputDialog(null,"Password : ","Resister",JOptionPane.INFORMATION_MESSAGE);
- int pass = Integer.parseInt(s);
- JOptionPane.showMessageDialog(null,"Resistered Successful","Resister",JOptionPane.INFORMATION_MESSAGE);*/
- }
- }
- @Override
- public void actionPerformed(ActionEvent ae) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }
- public class Lab11 {
- public static void main(String[] args) {
- JFrame frame = new Handelevent();
- frame.setTitle("Handelevent");
- frame.setSize(150, 110);
- frame.setLocation(550, 350);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- }
- class OkListener implements ActionListener{
- public void actionPerformed(ActionEvent e){
- JFrame x = new Login();
- x.setSize(250, 250);
- x.setLocation(550, 300);
- /*String s;
- s = JOptionPane.showInputDialog(null,"Name : ","Resister",JOptionPane.INFORMATION_MESSAGE);
- String name = s;
- s = JOptionPane.showInputDialog(null,"Email : ","Resister",JOptionPane.INFORMATION_MESSAGE);
- String email = s;
- s = JOptionPane.showInputDialog(null,"Password : ","Resister",JOptionPane.INFORMATION_MESSAGE);
- int pass = Integer.parseInt(s);
- JOptionPane.showMessageDialog(null,"Resistered Successful","Resister",JOptionPane.INFORMATION_MESSAGE);*/
- }
- }
- class CancelListener implements ActionListener{
- public void actionPerformed(ActionEvent e){
- String s;
- s = JOptionPane.showInputDialog(null,"Email : ","Login",JOptionPane.INFORMATION_MESSAGE);
- String email = s;
- s = JOptionPane.showInputDialog(null,"Password : ","Login",JOptionPane.INFORMATION_MESSAGE);
- int pass = Integer.parseInt(s);
- JOptionPane.showMessageDialog(null,"Login Successful","Login",JOptionPane.INFORMATION_MESSAGE);
- }
- }
- public void actionPerformed(ActionEvent ae) {
- String userName = userName_text.getText();
- String password = password_text.getText();
- if (userName.trim().equals("admin") && password.trim().equals("admin")) {
- message.setText(" Hello " + userName + "");
- } else {
- message.setText(" Invalid user.. ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement