Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.regex.Pattern;
- import javax.swing.*;
- public class Employee {
- public Employee() {
- JFrame jfrm = new JFrame("Employee Details ");
- jfrm.setLayout(new BorderLayout());
- jfrm.setSize(275, 100);
- jfrm.setMinimumSize(new Dimension(475, 300));
- jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jfrm.setVisible(true);
- JPanel jp1 = new JPanel(new GridLayout(5,2,20,20));
- jfrm.add(jp1);
- JLabel jl1=new JLabel(" Employee Id : ");
- JLabel jl2=new JLabel(" Name : ");
- JLabel jl3=new JLabel(" Username : ");
- JLabel jl4=new JLabel(" Password : ");
- JLabel jl5=new JLabel(" Mobile Number : ");
- JTextField t1 = new JTextField(10);
- JTextField t2 = new JTextField(10);
- JTextField t3 = new JTextField(10);
- JPasswordField t4 = new JPasswordField(10);
- JTextField t5 = new JTextField(10);
- jp1.add(jl1);
- jp1.add(t1);
- jp1.add(jl2);
- jp1.add(t2);
- jp1.add(jl3);
- jp1.add(t3);
- jp1.add(jl4);
- jp1.add(t4);
- jp1.add(jl5);
- jp1.add(t5);
- JPanel jp2= new JPanel(new FlowLayout(FlowLayout.CENTER));
- jfrm.add(jp2,BorderLayout.PAGE_END);
- JButton j1= new JButton("Sign Up");
- jp2.add(j1);
- j1.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String s=t2.getText();
- if(s.isEmpty())
- {
- JOptionPane.showMessageDialog(jp1,"Incorrect Name");
- }
- String str=t3.getText();
- Pattern str_regex=Pattern.compile("[A-Za-z0-9_*.]+@[a-z]+.[a-z]");
- if(str_regex.matcher(str).find()==false)
- {
- JOptionPane.showMessageDialog(jp1,"Incorrect Username");
- }
- String str1=t4.getText();
- Pattern str1_regex=Pattern.compile("[A-Z]++[a-z]++[0-9]++[_*.]+");
- if(str1_regex.matcher(str1).find()==false)
- {
- JOptionPane.showMessageDialog(jp1,"Incorrect Password");
- }
- String str2=t5.getText();
- Pattern str2_regex=Pattern.compile("[3-90-9]+");
- if(str2_regex.matcher(str2).find()==false)
- {
- JOptionPane.showMessageDialog(jp1,"Incorrect Mobile Number");
- }
- else if(str2.length()!=10)
- {
- JOptionPane.showMessageDialog(jp1,"Incorrect Mobile Number");
- }
- throw new UnsupportedOperationException("Not supported yet.");
- }
- });
- }
- }
- class Demo {
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run() {
- new Employee();
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment