/* 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. package testpak ; 

2.  

3. import java.awt.* ; 

4. import java.applet.* ; 

5. import java.awt.event.*; 

6.  

7. public class AccessApplet 

8.     extends Applet 

9.     implements ActionListener 

10.

11.   private Button  btn ; 

12.   private Access acc ; 

13.   private Accessextension accext ; 

14.  

15.   public 

16.   AccessApplet( ) 

17.   { 

18.     btn = new Button ( "Applet's Button" ) ; 

19.  

20.     acc = new Access (  ) ; 

21.     accext = new Accessextension (  ) ; 

22.   } 

23.  

24.   public void 

25.   init() 

26.   { 

27.     setLayout ( new GridLayout ( 1,0, 15,0 )  ) ; 

28.     add ( btn) ; 

29.  

30.     add ( acc ); 

31.     add ( accext ) ; 

32.  

33.     setBackground ( Color.yellow ) ; 

34.  

35.     validate() ; 

36.     btn.addActionListener ( this ) ; 

37.   } 

38.  

39.   public void 

40.   actionPerformed( ActionEvent ev ) 

41.   { 

42.     acc.lbl.setBackground ( Color.yellow ) ; 

43.     accext.lbx.setBackground ( Color.yellow ) ; 

44.   } 

45.

46. //////////// Access.java ///////////////// 

47. package testpak ; 

48.  

49. import java.awt.* ; 

50. import java.awt.event.*; 

51.  

52. public class Access 

53.     extends Panel 

54.

55.   protected Button  btacc ; 

56.  

57.   Label lbl ; 

58.  

59.   Access(  ) 

60.   { 

61.     btacc = new Button ( "Access Panel's Button" ) ; 

62.     add ( btacc ) ; 

63.     lbl = new Label ( "Access Panel" ); 

64.     add ( lbl ) ; 

65.     lbl.setBackground ( Color.white ) ; 

66.  

67.     validate() ; 

68.  

69.     setBackground ( Color.cyan ) ; 

70.   } 

71.

72. /////////// Accessextension.java /////////////////// 

73. package testpak ; 

74.  

75. import java.awt.* ; 

76. import java.awt.event.*; 

77.  

78. public class Accessextension 

79.     extends Access 

80.     implements MouseListener 

81.

82.   private TextField tf1 ; 

83.   Label lbx ; 

84.  

85.   Accessextension(  ) 

86.   { 

87.     tf1 = new TextField ( "text in TF" ); 

88.     add ( tf1 ) ; 

89.     lbx = new Label ( "Accessextension Panel" ); 

90.     add ( lbx ) ; 

91.     lbx.setBackground ( Color.green ) ; 

92.  

93.     validate() ; 

94.     tf1.addMouseListener ( this ) ; 

95.  

96.     setBackground ( Color.pink ) ; 

97.   } 

98.  

99.   public void mouseClicked(MouseEvent e) 

100.   { 

101.     btacc.setLabel ( "Changed by sub" ) ; 

102.   } 

103.  

104.   public void mousePressed(MouseEvent e)  {} 

105.   public void mouseReleased(MouseEvent e) {} 

106.   public void mouseEntered(MouseEvent e)  {} 

107.   public void mouseExited(MouseEvent e) {} 

108.

109.