/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import javax.swing.* ; 

2. import java.awt.* ; 

3. import java.awt.event.*; 

4. import java.util.Date

5. import java.text.* ; 

6.  

7. public class Dating2 

8.     extends JApplet 

9.     implements ActionListener 

10.

11.   JTextField tf, tf2 ; 

12.   JButton btn ; 

13.   Date dt ; 

14.   String tx ; 

15.  

16.   public void 

17.   actionPerformed ( ActionEvent ev ) 

18.   { 

19.     tx = tf.getText () ; 

20.  

21.     SimpleDateFormat sdf = 

22.       new SimpleDateFormat ( "dd-MM-yyyy" ) ; 

23.     sdf.setLenient ( false ) ; 

24.  

25.     dt = null

26.     try 

27.     { 

28.     dt = sdf.parse ( tx ) ; 

29.  

30.     tf2.setText ( "Date entered okay" ) ; 

31.     } 

32.     catch ( ParseException e ) 

33.     { 

34.       tf2.setText ( "Date entered not accepted" ) ; 

35.     } 

36.     tf.requestFocus (); 

37.   } 

38.   public void init () 

39.   { 

40.     tf2.setEditable ( false ) ; 

41.     Container cp = getContentPane(); 

42.     cp.setLayout( new FlowLayout() ); 

43.     cp.add( tf ) ; 

44.     cp.add ( tf2 ) ; 

45.     cp.add ( btn ) ; 

46.     tf.addActionListener ( this ) ; 

47.     btn.addActionListener ( this ) ; 

48.     cp.setBackground( Color.pink ) ; 

49.  

50.     tf.requestFocus (); 

51.     tf.selectAll (); 

52.   } 

53.   public Dating2() 

54.   { 

55.     tf = new JTextField ( "Enter date ,please" ) ; 

56.     tf2 = new JTextField ( 30 ) ; 

57.     btn = new JButton ( "Check, please" ) ; 

58.   } 

59.

60.