/* 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 java.awt.event.* ; 

2. import java.awt.* ; 

3. import java.applet.*; 

4.  

5. public class Catchem 

6.     extends Applet 

7.     implements ActionListener 

8.

9.   TextField tf ; 

10.   TextArea ta ; 

11.   Button bt ; 

12.   String [] tbl = { "Ichi", "Ni", "San" } ; 

13.  

14.   public void 

15.   actionPerformed ( ActionEvent ev ) 

16.   { 

17.     try 

18.     { 

19.     String tx = tf.getText (); 

20.     int inx = Integer.parseInt ( tx ) ; 

21.  

22.     ta.append ( "Element coming up , maybe\n" ) ; 

23.     ta.append ( tbl [ inx ]  + "\n" ) ; 

24.  

25.     ta.append ( "Another success\n" ); 

26.     } 

27.     catch ( NumberFormatException nfe ) 

28.     { 

29.       ta.append ( "WRONG ! You haven't typed a number\n" ) ; 

30.       ta.append ( "Exception specs : " + nfe + "\n") ; 

31.     } 

32.     catch ( IndexOutOfBoundsException iobe ) 

33.     { 

34.       ta.append ( "WRONG ! Valid indexes are 0, 1 and 2\n" ) ; 

35.       ta.append ( "Exception specs : " + iobe + "\n") ; 

36.     } 

37.     finally 

38.     { 

39.       ta.append ( "---> Whatever happens, this is done always\n" ) ; 

40.     } 

41.     ta.append 

42.     ( "If an exception has been caught, this is where we continue\n" ); 

43.     ta.append ( "====================================================\n" ); 

44.     tf.requestFocus (); 

45.     tf.selectAll (); 

46.   } 

47.   public 

48.   Catchem () 

49.   { 

50.     tf = new TextField ( 35 ) ; 

51.     ta = new TextArea ( 20, 60 ) ; 

52.     bt = new Button ( "Check, please" ) ; 

53.   } 

54.   public void 

55.   init() 

56.   { 

57.  

58.     add ( tf ) ; 

59.     add ( bt) ; 

60.     add ( ta ) ; 

61.     tf.addActionListener ( this ) ; 

62.     bt.addActionListener ( this ) ; 

63.     setBackground ( Color.yellow ) ; 

64.     tf.requestFocus (); 

65.     validate () ; 

66.   } 

67.

68. /*========  different source  ========== 

69. ..... 

70.     try 

71.     { 

72.       .... 

73.     } 

74.     catch ( IOException ioe ) 

75.     { 

76.       .... 

77.     } 

78.     catch ( EOFException eofe ) 

79.     { 

80.       .... 

81.     } 

82. */