nishimandhana

oop 10

Jul 29th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3. import java.awt.FlowLayout;
  4. import java.awt.GridLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.util.regex.Pattern;
  8. import javax.swing.*;
  9. public class Employee {
  10.  
  11.     public Employee() {
  12.    
  13.     JFrame jfrm = new JFrame("Employee Details ");
  14.     jfrm.setLayout(new BorderLayout());
  15.     jfrm.setSize(275, 100);
  16.     jfrm.setMinimumSize(new Dimension(475, 300));
  17.      jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18.    jfrm.setVisible(true);
  19.    
  20.    JPanel jp1 = new JPanel(new GridLayout(5,2,20,20));
  21.    jfrm.add(jp1);
  22.  
  23.    JLabel jl1=new JLabel(" Employee Id : ");
  24.    JLabel jl2=new JLabel(" Name : ");
  25.    JLabel jl3=new JLabel(" Username : ");
  26.    JLabel jl4=new JLabel(" Password : ");
  27.    JLabel jl5=new JLabel(" Mobile Number : ");
  28.    
  29.    JTextField t1 = new JTextField(10);
  30.    JTextField t2 = new JTextField(10);
  31.    JTextField t3 = new JTextField(10);
  32.    JPasswordField t4 = new JPasswordField(10);
  33.    JTextField t5 = new JTextField(10);
  34.    
  35.    jp1.add(jl1);
  36.    jp1.add(t1);
  37.    jp1.add(jl2);
  38.    jp1.add(t2);
  39.    jp1.add(jl3);
  40.    jp1.add(t3);
  41.    jp1.add(jl4);
  42.    jp1.add(t4);
  43.    jp1.add(jl5);
  44.    jp1.add(t5);
  45.    
  46.    JPanel jp2= new JPanel(new FlowLayout(FlowLayout.CENTER));
  47.    jfrm.add(jp2,BorderLayout.PAGE_END);
  48.    
  49.    
  50.    JButton j1= new JButton("Sign Up");
  51.    jp2.add(j1);
  52.    j1.addActionListener( new ActionListener() {
  53.  
  54.             public void actionPerformed(ActionEvent e) {
  55.                
  56.                 String s=t2.getText();
  57.                 if(s.isEmpty())
  58.                 {
  59.                      JOptionPane.showMessageDialog(jp1,"Incorrect Name");
  60.                 }
  61.                 String str=t3.getText();
  62.                 Pattern str_regex=Pattern.compile("[A-Za-z0-9_*.]+@[a-z]+.[a-z]");
  63.                 if(str_regex.matcher(str).find()==false)
  64.                 {
  65.                     JOptionPane.showMessageDialog(jp1,"Incorrect Username");
  66.                 }
  67.                
  68.                 String str1=t4.getText();
  69.                 Pattern str1_regex=Pattern.compile("[A-Z]++[a-z]++[0-9]++[_*.]+");
  70.                 if(str1_regex.matcher(str1).find()==false)
  71.                 {
  72.                     JOptionPane.showMessageDialog(jp1,"Incorrect Password");
  73.                 }
  74.                
  75.                 String str2=t5.getText();
  76.                 Pattern str2_regex=Pattern.compile("[3-90-9]+");
  77.                 if(str2_regex.matcher(str2).find()==false)
  78.                 {
  79.                     JOptionPane.showMessageDialog(jp1,"Incorrect Mobile Number");
  80.                 }
  81.                 else if(str2.length()!=10)
  82.                 {
  83.                     JOptionPane.showMessageDialog(jp1,"Incorrect Mobile Number");
  84.                 }
  85.                 throw new UnsupportedOperationException("Not supported yet.");
  86.             }
  87.             });
  88.    
  89.  
  90.     }
  91. }
  92.  
  93. class Demo {
  94.     public static void main(String[] args) {
  95.         SwingUtilities.invokeLater(new Runnable()
  96. {
  97.         public void run() {
  98.             new Employee();
  99.         }
  100. });
  101.     }
  102. }
Add Comment
Please, Sign In to add comment