Guest User

Untitled

a guest
Feb 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import java.awt.Button;
  2. import java.awt.Dimension;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.JPanel;
  10. import javax.swing.JTextField;
  11.  
  12. public class Registration extends JFrame implements ActionListener {
  13.  
  14. JFrame f;
  15. JPanel p;
  16. JTextField t1;
  17. JButton b1;
  18.  
  19. public Registration() {
  20. f = new JFrame();
  21. f.setPreferredSize(new Dimension(400, 400)); // size of JFrame
  22.  
  23. p = new JPanel();
  24. f.add(p);
  25.  
  26. t1 = new JTextField(8);
  27.  
  28. p.add(t1);
  29.  
  30. b1 = new JButton("check"); // creating a JButton
  31. b1.addActionListener(this); // adding action listener
  32. p.add(b1); // adding JButton to panel
  33.  
  34. f.pack();
  35.  
  36. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37. f.setVisible(true);
  38. }
  39.  
  40. public static void main(String[] args) {
  41. new Registration();
  42.  
  43. }
  44.  
  45. @Override
  46. public void actionPerformed(ActionEvent e) {
  47.  
  48. if (e.getSource() == b1) {
  49. if (t1.getText().length() == 10 && t1.getText().matches("[0-9]+")) { // validate
  50. // the
  51. // string
  52. JOptionPane.showMessageDialog(f, " valid string");
  53. } else {
  54. JOptionPane.showMessageDialog(f, " Invalid string");
  55.  
  56. }
  57.  
  58. }
  59. }
  60.  
  61. }
Add Comment
Please, Sign In to add comment